Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Connection Timeout between Network Queries

Reply
 
Old 09-15-2008   #1 (permalink)


Vista32bit
 
 

Connection Timeout between Network Queries

Essentially, with the help of a generous colleague, we built this script to do the following:

1) Over an internal corporate network we do a machine bios search (DNS search essentially) using a list we created from, say c:\systemlist.txt
2) We search these computers from #1 in a location on the remote machines in \c$\syslevel
3) The filename we're looking for, as an example, is test*.*
4) We then dump the results of whether it finds this test*.* successfully, or doesn't find it, or the network times out to a file c:\RESULTS.txt

The problem is this:

As the vbscript is going through the list some machines it won't obviously find on the network due to lag or the remote machine is not turned on.

How do I create a timeout that I can set for, say, 5-15seconds or whatever so that between scans of the computers in #1 it will only, say, scan the machine for 5seconds then just go to the next one in the list if no result was found? Remember, this is looking at the remote PCs name's via a DNS lookup and out network guys cannot change this so if I can do it artificially within the script so it doesn't have to wait up to 1-2mins to not find a machine then it would drastically cut down my query times.

My code:
Code:
on error resume next

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:\systemlist.txt", ForReading)
Wscript.Timeout = 5 
Wscript.echo objtextfile
' *************************************************************
' create the input array
strText = objTextFile.ReadAll
objTextFile.Close
arrComputers = Split(strText,vbcrlf)
' *************************************************************

Dim objFolder, objFile, TS
Dim strDirectory, strWildCard, strPattern
Dim strLog, blnFound, i
Dim objRegExpr

   'Create an instance of the regexp object
   Set objRegExpr = CreateObject("VBScript.RegExp")
   
   strWildCard = "test*.*"
   
   'Update the wildcard string to define a valid regular expression
   strPattern = Replace(strWildCard, ".", "\.")
   strPattern = Replace(strPattern, "*", ".*")
   strPattern = "^" & strPattern & "$"
   strPattern = Replace(strPattern, ".*$", ".+$")

   objRegExpr.Pattern = strPattern
   objRegExpr.Global = True
   objRegExpr.IgnoreCase = True

   'Set where you will log your findings
   strLog = "c:\RESULTS.txt"
   Set TS = objFSO.OpenTextFile(strLog,ForWriting,true) 
   

For i = 0 To UBound(arrComputers)
   'Get the directory you are searching
   strDirectory = "\\" & arrComputers(i) & "\c$\syslevel\"
   
   'Set your found flag
   blnFound = False
   
   'Check that that the directory exists. This shouldn't take  
   'long to retrun false if the machine can't be reached.
   If objFSO.FolderExists(strDirectory) Then
       'Get the current folder
       Set objFolder = objFSO.GetFolder(strDirectory)
       
       'Loop through all the files in the folder
       For Each objFile In objFolder.Files
           'Check if the file matches the wildcard search
           If objRegExpr.Test(objFile.Name) Then
               'Add file to log if found
               TS.WriteLine(arrComputers(i) & vbTab & objFile.Name)
               blnFound = True
           End If
       Next
   Else
       'Note in the log if the machine couldn't be reached
       TS.WriteLine(arrComputers(i) & " **Network Path could not be resolved**")
       blnFound = True
   End If
   
   'Add note if the file wasn't found
   If not blnFound Then
       TS.WriteLine(arrComputers(i) & vbTab & strWildCard & " not found")
   End if
   
   'Add an extra line to seperate the machines
   'TS.WriteLine("")


Next

TS.Close
Set TS = Nothing
Set objRegExpr = Nothing
   
MsgBox "QUERY COMPLETED!"
Thanks Vista community. Your help would be MOST appreciated here!

My System SpecsSystem Spec
Old 09-15-2008   #2 (permalink)
Richard Mueller [MVP]


 
 

Re: Connection Timeout between Network Queries


"thudo" <guest@xxxxxx-email.com> wrote in message
news:9b359bd335f48cef2b42f0165f937006@xxxxxx-gateway.com...
Quote:

>
> Essentially, with the help of a generous colleague, we built this script
> to do the following:
>
> 1) Over an internal corporate network we do a machine bios search (DNS
> search essentially) using a list we created from, say c:\systemlist.txt
> 2) We search these computers from #1 in a location on the remote
> machines in \c$\syslevel
> 3) The filename we're looking for, as an example, is test*.*
> 4) We then dump the results of whether it finds this test*.*
> successfully, or doesn't find it, or the network times out to a file
> c:\RESULTS.txt
>
> The problem is this:
>
> As the vbscript is going through the list some machines it won't
> obviously find on the network due to lag or the remote machine is not
> turned on.
>
> How do I create a timeout that I can set for, say, 5-15seconds or
> whatever so that between scans of the computers in #1 it will only, say,
> scan the machine for 5seconds then just go to the next one in the list
> if no result was found? Remember, this is looking at the remote PCs
> name's via a DNS lookup and out network guys cannot change this so if I
> can do it artificially within the script so it doesn't have to wait up
> to 1-2mins to not find a machine then it would drastically cut down my
> query times.
>
> My code:
>
> Code:
> --------------------
> on error resume next
>
> Const ForReading = 1
> Const ForWriting = 2
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> Set objTextFile = objFSO.OpenTextFile ("c:\systemlist.txt", ForReading)
> Wscript.Timeout = 5
> Wscript.echo objtextfile
> ' *************************************************************
> ' create the input array
> strText = objTextFile.ReadAll
> objTextFile.Close
> arrComputers = Split(strText,vbcrlf)
> ' *************************************************************
>
> Dim objFolder, objFile, TS
> Dim strDirectory, strWildCard, strPattern
> Dim strLog, blnFound, i
> Dim objRegExpr
>
> 'Create an instance of the regexp object
> Set objRegExpr = CreateObject("VBScript.RegExp")
>
> strWildCard = "test*.*"
>
> 'Update the wildcard string to define a valid regular expression
> strPattern = Replace(strWildCard, ".", "\.")
> strPattern = Replace(strPattern, "*", ".*")
> strPattern = "^" & strPattern & "$"
> strPattern = Replace(strPattern, ".*$", ".+$")
>
> objRegExpr.Pattern = strPattern
> objRegExpr.Global = True
> objRegExpr.IgnoreCase = True
>
> 'Set where you will log your findings
> strLog = "c:\RESULTS.txt"
> Set TS = objFSO.OpenTextFile(strLog,ForWriting,true)
>
>
> For i = 0 To UBound(arrComputers)
> 'Get the directory you are searching
> strDirectory = "\\" & arrComputers(i) & "\c$\syslevel\"
>
> 'Set your found flag
> blnFound = False
>
> 'Check that that the directory exists. This shouldn't take
> 'long to retrun false if the machine can't be reached.
> If objFSO.FolderExists(strDirectory) Then
> 'Get the current folder
> Set objFolder = objFSO.GetFolder(strDirectory)
>
> 'Loop through all the files in the folder
> For Each objFile In objFolder.Files
> 'Check if the file matches the wildcard search
> If objRegExpr.Test(objFile.Name) Then
> 'Add file to log if found
> TS.WriteLine(arrComputers(i) & vbTab & objFile.Name)
> blnFound = True
> End If
> Next
> Else
> 'Note in the log if the machine couldn't be reached
> TS.WriteLine(arrComputers(i) & " **Network Path could not be resolved**")
> blnFound = True
> End If
>
> 'Add note if the file wasn't found
> If not blnFound Then
> TS.WriteLine(arrComputers(i) & vbTab & strWildCard & " not found")
> End if
>
> 'Add an extra line to seperate the machines
> 'TS.WriteLine("")
>
>
> Next
>
> TS.Close
> Set TS = Nothing
> Set objRegExpr = Nothing
>
> MsgBox "QUERY COMPLETED!"
> --------------------
> Thanks Vista community. Your help would be MOST appreciated here!
>
>
> --
> thudo
You can use a ping function to check if the remote computers is available. I
have four examples linked here:

http://www.rlmueller.net/PingComputers.htm

The one you select depends on the OS. Also some do not allow you to specify
the timeout.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--


My System SpecsSystem Spec
Old 09-15-2008   #3 (permalink)


Vista32bit
 
 

Re: Connection Timeout between Network Queries

Hmmm but how do I integrate that the above script or do I run your script before running mine to produce a list of machines that are up? The problem is how to tell cscript to skip to the next machine in the list while still running the script? cscript's timeout only works when it cancels the whole script engine. So far you can do a timeout via a cscript command line like:
Code:
cscript //t:60 TEST2.vbs
Where it runs the .vbs with a timeout of 60seconds before the script discontinues BUT this cancels the entire script. There has to be another method inside vbscript to query the list for a selectable amount of time before it considers the result a TIMEOUT then proceed to next machine in the list?
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Timeout uploading to ftp through network drives. Vista networking & sharing
How to reduce WMI connection timeout? VB Script
The timeout period elapsed prior to obtaining a connection from th .NET General
Vista network quick to timeout Vista networking & sharing
Vista network quick to timeout Vista performance & maintenance


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46