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

実行可能ファイル名にはスペースが含まれているため、二重引用符で囲む必要があります。そうしないと、シェル オブジェクトが実行可能ファイルを実行しようとしますが、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
    
于 2013-08-19T13:20:54.147 に答える