VBScript来卸载windows应用程序
本文关键字:应用程序 windows 卸载 VBScript | 更新日期: 2023-09-27 18:28:16
我尝试使用VBScript卸载系统中已安装的windows应用程序exe。但无法卸载exe。请帮我一下。提前谢谢。
我尝试了以下代码:
Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."
'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{XXXXC6BA-0F96-4E3B-BB14-211E2805XXXX}"
'********************************
' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")
'**************************
UninstallString = "Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!''" &_
strComputer & "'root'default:StdRegProv")
strKeyPath = "SOFTWARE'Microsoft'Windows'CurrentVersion'Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
IF subkey = ProductCode Then
oShell.Run UninstallString, 1, True
End If
Next
Set oShell = Nothing
Set oReg = Nothing
修改代码
Dim oReg, oShell, oFSO
Dim UninstallString, ProductCode
Dim strComputer, colItems, objWMIService, objItem
Dim strKeyPath, subkey, arrSubKeys
strComputer = "."
'********************************
'Enter Product Code Of The Application Here That You Want To Uninstall within the Bracket
ProductCode = "{4AE9C6BA-0F96-4E3B-BB14-211E2805227E}"
'********************************
' Get scripting objects needed throughout script.
Set oShell = CreateObject("WScript.Shell")
'**************************
UninstallString = """C:'Program Files'ASCO'DatabaseUpgradeUtility'ASCO Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
'UninstallString = "ASCO Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
InputBox(UninstallString)
Const HKEY_LOCAL_MACHINE = &H80000002
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!''" &_
strComputer & "'root'default:StdRegProv")
strKeyPath = "SOFTWARE'Microsoft'Windows'CurrentVersion'Uninstall"
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
'IF subkey = ProductCode Then
'.Run UninstallString, 1, True
'End If
IF subkey = ProductCode Then
oShell.Run "%COMSPEC% /k " & UninstallString, 1, True
End If
Next
Set oShell = Nothing
Set oReg = Nothing
尝试了上面的和路径也trid去掉了双引号,但都不起作用。如果我必须在上面的脚本中更改任何内容,请提供给我。
您的可执行文件名中有空格,因此需要在其周围加上双引号,否则shell对象将尝试运行无法找到的可执行Database
。
更改此行:
UninstallString = "Database Upgrade Utility.exe /X" & ProductCode & " /qn" & " /norestart"
进入这个:
UninstallString = """Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
此外,请确保Database Upgrade Utility.exe
的路径位于PATH
环境变量中。如果不是,则需要使用其完整路径运行可执行文件。
UninstallString = """C:'Program Files'ASCO'DatabaseUpgradeUtility'ASCO Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"
如果这不起作用,请检查以下内容:
Run
语句是否首先执行?像这样更改条件,看看代码是否真的进入了Then
分支:IF subkey = ProductCode Then WScript.Echo "Subkey check OK." oShell.Run UninstallString, 1, True End If
卸载命令是否返回错误代码?
IF subkey = ProductCode Then rc = oShell.Run(UninstallString, 1, True) If rc <> 0 Then WScript.Echo "Command returned with status code " & rc & "." End If
卸载命令是否在控制台上产生输出?
IF subkey = ProductCode Then oShell.Run "%COMSPEC% /k " & UninstallString, 1, True End If