批处理脚本的初学者,我正在尝试制作批处理文件,检查程序是否在任务管理器中运行。如果应用程序正在运行,请运行更新文件,如果未安装该程序,请安装程序。以Adobe Reader为例。
@echo off
echo Installing Adobe Reader DC 150072033 Base...
echo This step will be omitted if it is unnecessary.
:B
tasklist | findstr /I "AcroRd32.exe"
if errorlevel 1 (call "msiexec /i AcroRdrDC1502020039.msi /qn") ELSE (timeout /t 30)
GOTO :B
echo.
echo Installing Adobe Reader DC Update Patches...
msiexec /p "AcroRdrUpd1502020039.msp" /qn"
echo.
echo Installation concluded.
希望您有一些建议或解决方案。 新年快乐:)
答案 0 :(得分:0)
也许下一个评论的代码段可以提供帮助:
@echo off
echo Installing Adobe Reader DC 150072033 Base...
echo This step will be omitted if it is unnecessary.
:B
rem check if Adobe Reader is currently running not if it's installed
tasklist | findstr /I "AcroRd32.exe"
if errorlevel 1 (
rem use `start` command instead of `call`
rem to ensure that current `bat` waits until `msiexec`'s finish
start "" /B /WAIT msiexec /i AcroRdrDC1502020039.msi /qn
) ELSE (
echo please exit Adobe Reader to continue
timeout /t 30
rem check again
GOTO :B
)
echo.
echo Installing Adobe Reader DC Update Patches...
msiexec /p "AcroRdrUpd1502020039.msp" /qn
echo.
echo Installation concluded.
请注意,tasklist | findstr /I "AcroRd32.exe"
会检查Adobe Reader当前是否正在运行。要检查Adobe Reader是否已安装,请按照此文档中的1.7 Identifying deployed applications部分进行操作:Enterprise Administration Guide for the Adobe® Acrobat Family of Products。
简而言之:检查 GUID注册表位置,请参见后一个文档:
GUID被写入各种位置。但是,Adobe 建议您使用以下内容:
- 32位Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Adobe\{application}\{version}\Installer\
- 64位Windows:
HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Adobe\{application}\{version}\Installer\
比照。还有这个帖子:Check if Adobe Reader is installed