Link to home
Start Free TrialLog in
Avatar of danfiggolf
danfiggolf

asked on

VBScript - Uninstall on Multiple PCs :: Erroring with (null): 0x80041021

Thanks for your help.  I assembled the following and it works, but I do get an error:
E:\scripts\removeit.vbs(9, 4) (null): 0x80041021

Any ideas why this little code piece kicks out the above error, please?

Const INPUT_FILE_NAME = "E:\scripts\Computers.txt"
Const FOR_READING = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
For Each strComputer In arrComputers
   Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
   Set colSoftware = objWMIService.ExecQuery _
    ("Select * from Win32_Product Where Name = 'Telestaff'")
   For Each objSoftware in colSoftware
    objSoftware.Uninstall()
   Next
Next
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of danfiggolf
danfiggolf

ASKER

Thanks Rob for the response.  I used the same example here: http://www.microsoft.com/technet/scriptcenter/resources/tales/sg1102.mspx

bringing in this code:
 Set colSoftware = objWMIService.ExecQuery _
             ("Select * from Win32_Product Where Name = 'Telestaff'")
            For Each objSoftware in colSoftware
             objSoftware.Uninstall()
            Next
Hi,

I just realised this a new question for one you asked previously.  I have also added a Ping function to check if the computer is awake before reading it, and also some error checking in case the software is not installed.....come to think of it, maybe that's the reason you were getting the iniial Null error to start with.....can you confirm that the software is actually installed on that particular machine that it was up to?

'============
Const INPUT_FILE_NAME = "E:\scripts\Computers.txt"
Const FOR_READING = 1
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(INPUT_FILE_NAME, FOR_READING)
strComputers = objFile.ReadAll
MsgBox strComputers
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
For Each strComputer In arrComputers
      boolResult = Ping(strComputer)      
      If boolResult = True Then
            Set objWMIService = GetObject("winmgmts:" _
             & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
            Set colSoftware = objWMIService.ExecQuery _
                  ("SELECT * FROM Win32_Product Where Name = 'Telestaff'", "WQL", _
                        wbemFlagReturnImmediately + wbemFlagForwardOnly)
            ' If the query returned no records, an error will occur
            ' so we place On Error Resume Next to ignore the error,
            ' then we check the error code two lines later
            On Error Resume Next
            For Each objSoftware in colSoftware
                  If Err.Number = 0 Then
                        On Error GoTo 0
                        MsgBox "Software found on " & strComputer
                        'objSoftware.Uninstall()
                  Else
                        Err.Clear
                        On Error GoTo 0
                        MsgBox "No installations of this product were found on " & strComputer
                  End If
            Next
      Else
            MsgBox "Could not ping " & strComputer
      End If
Next

Function Ping(strComputer)
      Dim objShell, boolCode
      Set objShell = CreateObject("WScript.Shell")
      boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
      If boolCode = 0 Then
            Ping = True
      Else
            Ping = False
      End If
End Function
'=============

Regards,

Rob.
The result of this script is it sends a msgbox first of the contents of all the computers in the computers.txt file and then sits in a hold state.  I had to break the script run.  I believe it must be at the ping point of the script.
strComputers = objFile.ReadAll
MsgBox strComputers
objFile.Close
arrComputers = Split(strComputers, vbCrLf)
For Each strComputer In arrComputers
      boolResult = Ping(strComputer)      
How would I input trap points in the script to see what is happening in this script effort?
Hello Rob,

What your script is working fine for me.  Thanks.  What is happening is I need to understand why it reports that the application is installed on my test computer, when actually it was removed.  I look into the program files path and there is no file structure left, since it was uninstalled. I guess it shows in wbem that it's still installed.
Hi,

The "hold" state that you mentioned should not be at the Ping point, that is just a quick Ping test that should return quickly.  The point it is most likely stalling at, is the GetObject command where it connects to the remote computer.  Sometimes if WMI is misconfigured, this can take a very long time, and also error out.

But, if it is working, and does obtain the results of the Win32_Product class, then it should tell you whether the the particular program was installed by the Windows Installer.

So if it *does* say that it still exists in the Win32_Product class, then it most likely was not removed completely, or properly, using the Windows Installer uninstall utility (just the "Remove" button in Add / Remove programs).

Can you check if the program is still listed in Add / Remove programs?

Regards,

Rob.