troubleshooting Question

VBScript hangs due to rights issue

Avatar of JenH2
JenH2Flag for United States of America asked on
VB Script
12 Comments1 Solution664 ViewsLast Modified:
I'm working on a script that reads a list of computer names, then for each one it connects to the system and inventories it for Adobe products.  I'm running the script with domain admin rights, however there seem to be a few systems that have removed "Domain Admins" from their local admin group.  When the script gets to the part where it queries the system it just hangs, rather than just move on (via On Error Resume Next).  Can anyone help me with a work around for this?

I run the script with CScript.exe so all the Echo commands show me the progress of each system and it always hangs when it echoes "Inventorying..." when it hits a system that I don't have access to.
Const ForAppending = 8
Const ForReading = 1
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("C:\Scripts\adobeinventory.csv", ForAppending, True)
Set objComputerList = objFSO.OpenTextFile("C:\Scripts\computers.txt",ForReading)
Set objShell = WScript.CreateObject("Wscript.Shell")
 
objTextFile.WriteLine "Computer Name" & "," & "Description" & "," & "Version" 
 
Do Until objComputerList.AtEndOfStream    
On Error Resume Next
   strComputer = objComputerList.ReadLine
   WScript.Echo "Starting " & strComputer & "..."
   cmdPing = "for /f ""delims=."" %I in ('ping -n 1 "&strComputer&"') do if ""%I""==""Request timed out"" (exit 55)"
   cmdReturn = objShell.run("cmd /c "+ cmdPing,0,true)
 
   If cmdReturn=0 Then
      cmdPing = "for /f ""delims=."" %I in ('ping -n 1 "&strComputer&"') do if ""%I""==""Ping request could not find host "&strComputer&""" (exit 65)"
      cmdReturn = objShell.run("cmd /c "+ cmdPing,0,true)
         If cmdreturn=0 Then
            WScript.Echo "Ping successful."
            Err.Clear
            Set objComputer = GetObject("LDAP://cn=" & strComputer & ",cn=Computers,dc=domain,dc=com")
            If Err.Number = 0 Then
               WScript.Echo "System on the domain."
               Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	
               'Get list of software installed
               WScript.Echo "Inventorying..."
               Set colSoftware = objWMIService.ExecQuery ("Select * from Win32_Product where Description like '%adobe%'")
               For Each objSoftware in colSoftware
                  objTextFile.WriteLine strComputer & "," & objSoftware.Description & "," & objSoftware.Version
               Next
	
               Set objWMIService = "Nothing"
               Set colSoftware = "Nothing"
            Else
               WScript.Echo "System in a Workgroup."	
            End If
         Else
            WScript.Echo "Ping failed."
         End If
    End If
    WScript.Echo strComputer & " was successfully inventoried."
Loop
 
objTextFile.Close
Wscript.echo "Done"
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros