This script connects to systems listed in a file and runs the systeminfo cmd, returning the output to stdout where it's captured and written to a text file. All works well until I come across one system that is online but does not respond to the system info cmd. At that point the script waits forever. How can I set some sort of timeout on the cmd execution for that line of code?
I took a look at wscript.timeout but that did not help. I am running the script with a domain admin privilege so I don't think there are any authority issues.
TIA
on error resume next
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("\\myserver\ret\RetSys_Support\Equipment & Software Docs\Misc Files\sysdata\retcomps.asc", ForReading)
Wscript.echo objtextfile
' *************************************************************
' create the input array
strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText,vbcrlf)
' *************************************************************
For Each strComputer in arrComputers
dim strvalue
strvalue = ""
strvalue = lastusr(trim(strcomputer))
' show last logged on user and computer name
wscript.echo strvalue & " " & strcomputer
Set objShell = CreateObject("WScript.Shell")
********* problem here ************
Set objExecObject = objShell.exec ("%comspec% /c systeminfo.exe /S \\" & strcomputer)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
' open output file
strtext = "User:" & vbtab & strusr & strvalue & vbcrlf & strtext
ofile = "\\myserver\share\scripts\LastUser\Usr2model\" & strvalue & strcomputer & ".txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile (ofile, ForWriting, True)
objFile.Write strText
objFile.Close
Loop
next
' ************************************************************
public function lastusr(strcomputer)
Set objRegistry = Nothing
Set objRegistry = GetObject("WinMgmts:{impersonationLevel=impersonate}\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"
strValueName = "DefaultUserName"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strvalue
lastusr = strvalue
end Function
Mike Butler
Now former Iseries Guy -> PC's back, SUNs gone Iseries gone- BooHoo
"Never put off 'til tomorrow what you should have done yesterday
I took a look at wscript.timeout but that did not help. I am running the script with a domain admin privilege so I don't think there are any authority issues.
TIA
on error resume next
Const HKEY_LOCAL_MACHINE = &H80000002
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("\\myserver\ret\RetSys_Support\Equipment & Software Docs\Misc Files\sysdata\retcomps.asc", ForReading)
Wscript.echo objtextfile
' *************************************************************
' create the input array
strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText,vbcrlf)
' *************************************************************
For Each strComputer in arrComputers
dim strvalue
strvalue = ""
strvalue = lastusr(trim(strcomputer))
' show last logged on user and computer name
wscript.echo strvalue & " " & strcomputer
Set objShell = CreateObject("WScript.Shell")
********* problem here ************
Set objExecObject = objShell.exec ("%comspec% /c systeminfo.exe /S \\" & strcomputer)
Do While Not objExecObject.StdOut.AtEndOfStream
strText = objExecObject.StdOut.ReadAll()
' open output file
strtext = "User:" & vbtab & strusr & strvalue & vbcrlf & strtext
ofile = "\\myserver\share\scripts\LastUser\Usr2model\" & strvalue & strcomputer & ".txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile (ofile, ForWriting, True)
objFile.Write strText
objFile.Close
Loop
next
' ************************************************************
public function lastusr(strcomputer)
Set objRegistry = Nothing
Set objRegistry = GetObject("WinMgmts:{impersonationLevel=impersonate}\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\WinLogon"
strValueName = "DefaultUserName"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strvalue
lastusr = strvalue
end Function
Mike Butler
Now former Iseries Guy -> PC's back, SUNs gone Iseries gone- BooHoo
"Never put off 'til tomorrow what you should have done yesterday