0

我尝试使用 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

尝试了上述方法,路径也没有双引号,但两者都不起作用。如果我必须在上面的脚本中更改任何内容,请提供给我。

4

1 回答 1

0

您的可执行文件名称中包含空格,因此您需要在其周围加上双引号,否则 shell 对象将尝试运行Database无法找到的可执行文件。

更改此行:

UninstallString = "Database Upgrade Utility.exe /X" & ProductCode & " /qn" & "   /norestart"

进入这个:

UninstallString = """Database Upgrade Utility.exe"" /X" & ProductCode & " /qn /norestart"

另外,请确保到的路径Database Upgrade Utility.exePATH环境变量中。如果不是,您需要使用其完整路径运行可执行文件。

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
    
于 2013-08-19T13:20:54.147 回答