script for uninstalling application
I am trying to uninstall application. Here is the VBscript I use:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Jobs =Array("'AppName1'", "'AppName2'", "AppName3'")
For Each Job in Jobs
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = " & Job)
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
Next
It fails on Windows Server 2003 with the following message: SWbemObjectSet: Invalid class...
Does anybody know what I am doing wrong?
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Jobs =Array("'AppName1'", "'AppName2'", "AppName3'")
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = " & Job)
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
Next
Does anybody know what I am doing wrong?
0 Comments
[ + ] Show comments
Answers (5)
Please log in to answer
Posted by:
aogilmor
16 years ago
ORIGINAL: Leana
I am trying to uninstall application. Here is the VBscript I use:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Jobs =Array("'AppName1'", "'AppName2'", "AppName3'")
For Each Job in Jobs
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product Where Name = " & Job)
For Each objSoftware in colSoftware
objSoftware.Uninstall()
Next
Next
It fails on Windows Server 2003 with the following message: SWbemObjectSet: Invalid class...
Does anybody know what I am doing wrong?
It soiunds like it's not finding the
Also, I'd recommned using IdentifyingNumber instead of Name.
Posted by:
anonymous_9363
16 years ago
ORIGINAL: aogilmorI think it's more likely an issue with WMI itself. I can almost guarantee you have chunks of registry missing. See http://windowsxp.mvps.org/repairwmi.htm
Try reinstalling the scripting engine.
Posted by:
makelley
16 years ago
here is one we use to remove previous versions. Just replace the GUID(s) and you should not have any problems.
Option Explicit
' Evaluate the command line options for uninstall
Dim strMode, objArgs, I
strMode = "/qn"
Set objArgs = WScript.Arguments
For I = 0 To objArgs.Count - 1
Select Case LCase(objArgs(I))
Case "/qr"
strMode = "/qr"
Case "/qb"
strMode = "/qb"
Case "/qb+"
strMode = "/qb+"
Case "/qb!"
strMode = "/qb!"
Case "/qn"
strMode = "/qn"
Case Else
strMode = "/qb!"
End Select
Next
' Set Install State constants
Const msiInstallStateNotUsed = -7
Const msiInstallStateBadConfig = -6
Const msiInstallStateIncomplete = -5
Const msiInstallStateSourceAbsent = -4
Const msiInstallStateInvalidArg = -2
Const msiInstallStateUnknown = -1
Const msiInstallStateBroken = 0
Const msiInstallStateAdvertised = 1
Const msiInstallStateRemoved = 1
Const msiInstallStateAbsent = 2
Const msiInstallStateLocal = 3
Const msiInstallStateSource = 4
Const msiInstallStateDefault = 5
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim ProductCode, MSIState
' get path to this script
Set fileSys = CreateObject("Scripting.FileSystemObject") : CheckError
Dim folder:folder = fileSys.GetAbsolutePathName(".")
On Error Resume Next
' Insert the ProductCode for each MSI you want to uninstall
For Each ProductCode In Array(_
"{AC76BA86-1033-0000-BA7E-000000000003}",_
"{AC76BA86-1033-0000-7760-000000000002}",_
"{AC76BA86-1033-0000-7760-100000000001}",_
"{AC76BA86-1033-0000-7760-000000000003}")
If installer.ProductState(ProductCode) <> msiInstallStateUnknown Then
If installer.ProductState(ProductCode) <> msiInstallStateInvalidArg Then
If installer.ProductState(ProductCode) <> msiInstallStateAbsent Then
WshShell.Run "C:\Windows\System32\Msiexec.exe /x " & ProductCode & " " & strMode & " REMOVE=ALL REBOOT=ReallySuppress", 1, True
End If
End If
End If
Next
Option Explicit
' Evaluate the command line options for uninstall
Dim strMode, objArgs, I
strMode = "/qn"
Set objArgs = WScript.Arguments
For I = 0 To objArgs.Count - 1
Select Case LCase(objArgs(I))
Case "/qr"
strMode = "/qr"
Case "/qb"
strMode = "/qb"
Case "/qb+"
strMode = "/qb+"
Case "/qb!"
strMode = "/qb!"
Case "/qn"
strMode = "/qn"
Case Else
strMode = "/qb!"
End Select
Next
' Set Install State constants
Const msiInstallStateNotUsed = -7
Const msiInstallStateBadConfig = -6
Const msiInstallStateIncomplete = -5
Const msiInstallStateSourceAbsent = -4
Const msiInstallStateInvalidArg = -2
Const msiInstallStateUnknown = -1
Const msiInstallStateBroken = 0
Const msiInstallStateAdvertised = 1
Const msiInstallStateRemoved = 1
Const msiInstallStateAbsent = 2
Const msiInstallStateLocal = 3
Const msiInstallStateSource = 4
Const msiInstallStateDefault = 5
On Error Resume Next
Dim installer : Set installer = Nothing
Set installer = Wscript.CreateObject("WindowsInstaller.Installer")
Dim WshShell
Set WshShell = WScript.CreateObject("WScript.Shell")
Dim ProductCode, MSIState
' get path to this script
Set fileSys = CreateObject("Scripting.FileSystemObject") : CheckError
Dim folder:folder = fileSys.GetAbsolutePathName(".")
On Error Resume Next
' Insert the ProductCode for each MSI you want to uninstall
For Each ProductCode In Array(_
"{AC76BA86-1033-0000-BA7E-000000000003}",_
"{AC76BA86-1033-0000-7760-000000000002}",_
"{AC76BA86-1033-0000-7760-100000000001}",_
"{AC76BA86-1033-0000-7760-000000000003}")
If installer.ProductState(ProductCode) <> msiInstallStateUnknown Then
If installer.ProductState(ProductCode) <> msiInstallStateInvalidArg Then
If installer.ProductState(ProductCode) <> msiInstallStateAbsent Then
WshShell.Run "C:\Windows\System32\Msiexec.exe /x " & ProductCode & " " & strMode & " REMOVE=ALL REBOOT=ReallySuppress", 1, True
End If
End If
End If
Next
Posted by:
Leana
16 years ago
Thank you! This worked... the only downside, I guess, is that in order to uninstall with Msiexec.exe you need to have original installers...
.........Actually no. I just realized you don't need original installers. Here is the function for getting ProductCode in case anybody needs it:
Function GetProductCode(productName)
'// Default to empty variable return
GetProductCode = vbEmpty
'// Variables
Dim installer: Set installer = CreateObject("WindowsInstaller.Installer")
Dim productCode
Const msiOpenDatabaseModeReadOnly = 0
Const msiInstallStateNotUsed = -7
'// Check for obj err
If err.number <> 0 Then Exit Function
'// Verify the client is available to find
If installer.ProductState(productName) <> msiInstallStateUnknown Then
'// Search for the client
For Each productCode In installer.Products
If LCase(productName) = LCase(installer.ProductInfo(productCode, "ProductName")) Then
GetProductCode = productCode
Exit Function
End If
Next
Else
'// Client isn't installed or cannot be found by the correct name
End If
End Function
.........Actually no. I just realized you don't need original installers. Here is the function for getting ProductCode in case anybody needs it:
'// Default to empty variable return
GetProductCode = vbEmpty
'// Variables
Dim installer: Set installer = CreateObject("WindowsInstaller.Installer")
Dim productCode
Const msiOpenDatabaseModeReadOnly = 0
Const msiInstallStateNotUsed = -7
'// Check for obj err
If err.number <> 0 Then Exit Function
'// Verify the client is available to find
If installer.ProductState(productName) <> msiInstallStateUnknown Then
'// Search for the client
For Each productCode In installer.Products
If LCase(productName) = LCase(installer.ProductInfo(productCode, "ProductName")) Then
GetProductCode = productCode
Exit Function
End If
Next
Else
'// Client isn't installed or cannot be found by the correct name
End If
End Function
Posted by:
sellorderon
13 years ago
ORIGINAL: Leana
Set colSoftware = objWMIService.ExecQuery _
   ("Select * from Win32_Product Where Name = " & Job)
ÂÂ
It fails on Windows Server 2003 with the following message: SWbemObjectSet: Invalid class...
Does anybody know what I am doing wrong?
Set colSoftware = objWMIService.ExecQuery("Select * from Win32_Product Where Name = '" & Job &"'")
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.