desktoprat
MIS
The script below works for the most part, but I am having a problem with the problem PCs and would like a comment or two.
My test file has 3 PCs listed. The 1st and 3rd are turned on and are accessible. The 2nd is turned off. Theoretically, I will see inventories of 2 PCs on the output file and the single bad PC in the failed.txt file. In actuality, it inventories the 1st, lists the 2nd and ends the script w/o looking at #3. Take the problem PC out and it inventories both 1 & 3. My question now is why???
softinv7.vbs
On Error Resume Next
computer = InputBox("Enter COMPLETE path to the source file","Input source","c:\scripts\lists\")
badPC = inputbox ("Enter the name of problem PCs"," ","c:\scripts\output\failed.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set invOut = objFSO.CreateTextFile("c:\scripts\output\software.tsv", True)
set failedmachines=objFSO.createtextfile(badPC)
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
invOut.WriteLine "IP Address" & vbTab & "Caption" & vbtab & _
"Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Name" & vbtab & _
"Package Cache" & vbtab & "Vendor" & vbtab _
& "Version"
Set objTextFile = objFSO.OpenTextFile _
(computer, ForReading)
Do Until objTextFile.AtEndOfStream
StrComputer = objTextFile.Readline
call invsoft
Loop
invOut.Close
MsgBox "Software is now inventoried"
'=================================================================
Sub invsoft
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err Then
HandleErr()
Err.Clear
Else
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")
For Each objSoftware in colSoftware
invOut.WriteLine strComputer & vbtab & _
objSoftware.Caption & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version
Next
End If
End Sub
'=================================================================
'=================================================================
Sub HandleErr()
failedmachines.WriteLine strComputer & " " & "Had error # " & Err.Number
End Sub
'=========================================================
My test file has 3 PCs listed. The 1st and 3rd are turned on and are accessible. The 2nd is turned off. Theoretically, I will see inventories of 2 PCs on the output file and the single bad PC in the failed.txt file. In actuality, it inventories the 1st, lists the 2nd and ends the script w/o looking at #3. Take the problem PC out and it inventories both 1 & 3. My question now is why???
softinv7.vbs
On Error Resume Next
computer = InputBox("Enter COMPLETE path to the source file","Input source","c:\scripts\lists\")
badPC = inputbox ("Enter the name of problem PCs"," ","c:\scripts\output\failed.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set invOut = objFSO.CreateTextFile("c:\scripts\output\software.tsv", True)
set failedmachines=objFSO.createtextfile(badPC)
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
invOut.WriteLine "IP Address" & vbTab & "Caption" & vbtab & _
"Identifying Number" & vbtab & _
"Install Date" & vbtab & "Install Location" & vbtab & _
"Name" & vbtab & _
"Package Cache" & vbtab & "Vendor" & vbtab _
& "Version"
Set objTextFile = objFSO.OpenTextFile _
(computer, ForReading)
Do Until objTextFile.AtEndOfStream
StrComputer = objTextFile.Readline
call invsoft
Loop
invOut.Close
MsgBox "Software is now inventoried"
'=================================================================
Sub invsoft
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
If Err Then
HandleErr()
Err.Clear
Else
Set colSoftware = objWMIService.ExecQuery _
("Select * from Win32_Product")
For Each objSoftware in colSoftware
invOut.WriteLine strComputer & vbtab & _
objSoftware.Caption & vbtab & _
objSoftware.IdentifyingNumber & vbtab & _
objSoftware.InstallDate & vbtab & _
objSoftware.InstallLocation & vbtab & _
objSoftware.Name & vbtab & _
objSoftware.PackageCache & vbtab & _
objSoftware.Vendor & vbtab & _
objSoftware.Version
Next
End If
End Sub
'=================================================================
'=================================================================
Sub HandleErr()
failedmachines.WriteLine strComputer & " " & "Had error # " & Err.Number
End Sub
'=========================================================