2013-08-19 136 views
0

我試圖卸載已安裝在我的系統中使用VBScript的Windows應用程序EXE。但是無法卸載exe。請幫助我。提前致謝。VBScript卸載Windows應用程序

我試着用下面的代碼:

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了雙引號也但兩者都沒有工作。如果有任何需要更改上述腳本的內容,請提供給我。

+1

'... 「數據庫升級Utility.exe/X」 ...'看起來像是乞求各地的可執行文件的名字報價。 – cHao

+1

「不工作」是一個不充分的問題描述。如何* execatly *是「不工作」?你在'CMD'窗口中得到了什麼輸出?命令的返回值是多少?你是否確認它正在運行? –

回答

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 
    
+0

我試過以下修改,但不卸載... UninstallString =「C:\ Program Files \ ASCO \ DatabaseUpgradeUtility \ ASCO數據庫升級Utility.exe/X」和ProductCode&「/ qn/norestart」 – user1000549

+0

@ user1000549同樣,帶空格**的路徑必須放在雙引號之間。請重新閱讀我的答案。另外,可執行文件名和'/ X'之間沒有空格。 –

+0

嘗試像dis ... UninstallString =「C:\ Program Files \ ASCO \ DatabaseUpgradeUtility \」「ASCO數據庫升級Utility.exe」「/ X」&ProductCode&「/ qn /norestart"..not working .. – user1000549