/bundles/itninjaweb/img/Breadcrumb_cap_w.png
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?
0 Comments   [ - ] Hide Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
Answer this question or Comment on this question for clarity

Answers

0
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 Win32_Product class, but why that would be I don't know. Try reinstalling the scripting engine.

Also, I'd recommned using IdentifyingNumber instead of Name.
Answered 07/24/2008 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
0
ORIGINAL: aogilmor
Try reinstalling the scripting engine.
I 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
Answered 07/25/2008 by: VBScab
Red Belt

Please log in to comment
0
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
Answered 07/29/2008 by: makelley
Senior Yellow Belt

Please log in to comment
0
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
Answered 08/04/2008 by: Leana
Senior Yellow Belt

Please log in to comment
0
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 &"'")
Answered 06/23/2011 by: sellorderon
Yellow Belt

Please log in to comment