[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2131
  • Last Modified:

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
0
danfiggolf
Asked:
danfiggolf
  • 4
  • 3
1 Solution
 
RobSampsonCommented:
Hi, do you have empty lines in the text file that it opens?  It would seems that strComputer is Null when the GetObject method tries to connect to a computer.
Try checking if strComputer is null before calling GetObject:
'===============
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
      If IsNull(strComputer) = False Then
            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
      End If
Next
'================

Regards,

Rob.
0
 
danfiggolfAuthor Commented:
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
0
 
RobSampsonCommented:
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.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
danfiggolfAuthor Commented:
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)      
0
 
danfiggolfAuthor Commented:
How would I input trap points in the script to see what is happening in this script effort?
0
 
danfiggolfAuthor Commented:
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.
0
 
RobSampsonCommented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now