我正在尝试通过从注册表中提取 UninstallString 来使用批处理文件来卸载某个程序的任何实例。我以前在这方面取得了成功,但不确定我在这里缺少什么。
这是有问题的代码:
REM Loop thru Uninstall keys
ECHO Checking installed programs list for myAPP.
FOR /F "tokens=*" %%A IN ('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall') DO (
REM For each uninstall key, look for the DisplayName to match our application.
FOR /F "tokens=3" %%B IN ('reg query "%%A" /v DisplayName') DO (
REM If it's our application, uninstall it.
IF "%%B" == "myAPP" (
ECHO Found %%B at %%A
FOR /F "tokens=3*" %%C IN ('reg query "%%A" /v UninstallString') DO (
ECHO Uninstalling instance.
ECHO %%C %%D
start /wait %%C %%D
)
)
)
)
该ECHO %%C %%D
语句按预期工作,但该start /wait %%C %%D
行没有。
之前的输出start
:
Checking installed programs list for myAPP
Found myAPP at HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Uninstall\1139844978.www.myDOMAIN.local
Uninstalling instance.
c:\Program Files (x86)\Microsoft Silverlight\5.1.20125.0\Silverlight.Configuration.exe -uninstallApp 1139844978.www.myDOMAIN.local
但是该start
命令给了我一个错误,说找不到“C:\ Program”,这告诉我它没有像我想象的那样使用整个 UninstallString,基于它Echo
之前的结果。
任何帮助,将不胜感激!
更新:
得到它的工作。由于某种原因,FOR
循环在 C:\Program 和字符串的其余部分之间分裂,我不明白,因为该路径的其余部分还有其他空格。
无论如何,我能够使用另一个FOR
循环来拆分字符串并将程序START
调用与传递的参数分开。
我不认为这是一个理想的解决方案,因为它只是因为这个特定的UninstallString的格式化方式而起作用,但它确实有效。
这是更新的代码:
:isInstalled
REM Loop thru Uninstall keys
ECHO Checking if already installed.
FOR /F "tokens=*" %%A IN ('reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Uninstall') DO (
REM For each uninstall key, look for the DisplayName to match our application.
FOR /F "tokens=3" %%B IN ('reg query "%%A" /v DisplayName') DO (
REM If it's our application, uninstall it.
IF "%%B" == "myAPP" (
ECHO Found %%B at %%A
FOR /F "tokens=3*" %%C IN ('reg query "%%A" /v UninstallString') DO (
ECHO Uninstalling instance.
FOR /F "tokens=1,2 delims=-" %%E IN ('ECHO %%~C %%~D') DO (
START /wait "" "%%E" -%%F
)
)
)
)
)