Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connection timeout

Status
Not open for further replies.

edo74

Technical User
Oct 29, 2003
7
SK
Hello Scripters,

Having a problem:
when I run my scripts, a sample:
(finds user logged on somewhere on the net.)

*****************************************
Dim objDomain, objShell, objExecObject
Dim compSystem, strUser, strComputer
Set objShell = WScript.CreateObject("WScript.Shell")
Set ObjDomain = GetObject("WinNT://DOMAIN")

WScript.stdOut.Write "User to be found (domain\user_name): "
strUser = WScript.stdIn.ReadLine
WScript.Echo "Looking for user: " & strUser

strUser = UCase(strUser)

ObjDomain.Filter = Array("Computer")

On Error Resume Next

for each strComputer in objDomain
Set objExecObject = objShell.Exec("%comspec% /c ping.exe -n 1 " & strComputer.name)
Do until objExecObject.stdOut.AtEndOfStream
strLine = objExecObject.stdOut.Readline()
strReply = Instr(strLine, "Reply")
If strReply <> 0 Then
For Each compSystem in Getobject(&quot;winmgmts:&quot; & &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer.name).InstancesOf(&quot;Win32_ComputerSystem&quot;)
WScript.stdOut.Write(&quot;.&quot;)
If UCase(compSystem.userName) = strUser Then
WScript.stdOut.WriteLine vbcrlf & compSystem.name
End If
Next
End If
Loop
Next
WScript.Echo vbcrlf & &quot;Done!&quot;
*******************************************

it hangs on some computers for a few minutes (up to 5-10 min.), other computers are processed within 10-30 seconds. The script is run on WIN 2K SP4 station and stations in my domain (NT domain - NT4.0 Servers) are mostly WIN2K. Is there a way to set a timeout for connection to remote PC?

thanx,

eduard
 
Hello edo74,

Try the modified line see if it improves.
Code:
'after the for each line
Set objExecObject = objShell.Exec(&quot;%comspec% /c ping.exe -n 1 -w 1000&quot; & strComputer.name)
do while objExecObject.status = 0
    wscript.sleep 100
loop
'continue with the do loop
regards - tsuji
 
Hi tsuji,

I meant something different. My point was: when I make a connection to a remote PC, using WMI, e.g.:
*******
For Each compSystem in Getobject(&quot;winmgmts:&quot; & &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer.name).InstancesOf(&quot;Win32_ComputerSystem&quot;)
*******
the script hangs, like there is a problem with remote WMI or the operating system. Is there a way to make a timeout for this connection?
THANX,

eduard
 
Hello again,

[1] Take away %comspec% /c call. It may pose problem.
[2] If &quot;Reply&quot; is the only signature tested, use readall.
[3] In any case, I would control the exec to make sure everything run synchronously in the context.
Code:
for each strComputer in objDomain
Set objExecObject = objShell.Exec(&quot;%comspec% /c ping.exe -n 1 &quot; & strComputer.name)
do while objExecObject.status = 0
    wscript.sleep 100
loop
strOut = objExecObject.stdOut.Readall
strReply = Instr(strOut, &quot;Reply&quot;)
If strReply <> 0 Then
    For Each compSystem in Getobject(&quot;winmgmts:&quot; & &quot;{impersonationLevel=impersonate}!\\&quot; & strComputer.name).InstancesOf(&quot;Win32_ComputerSystem&quot;)  
        WScript.stdOut.Write(&quot;.&quot;)
        If UCase(compSystem.userName) = strUser Then
            WScript.stdOut.WriteLine vbcrlf & compSystem.name  
        End If  
    Next  
End If
Next
See if it makes sense.

regards - tsuji
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top