Windows Vista Forums

Connection Timeout between Network Queries
  1. #1



    Newbie
    Join Date : Sep 2008
    Posts : 2
    Vista32bit
    Local Time: 06:51 PM

    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

  2. #2


    Richard Mueller [MVP] Guest

    Re: Connection Timeout between Network Queries


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

    >
    > 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

  3. #3



    Newbie
    Join Date : Sep 2008
    Posts : 2
    Vista32bit
    Local Time: 06:51 PM


      Thread Starter

    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

Connection Timeout between Network Queries problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to reduce WMI connection timeout? D.P. Roberts VB Script 2 07 Aug 2008
The timeout period elapsed prior to obtaining a connection from th John Staggs .NET General 7 27 Mar 2008
Vista network quick to timeout CMoya Vista General 3 12 Feb 2008
Vista network quick to timeout CMoya Vista networking & sharing 3 12 Feb 2008
Vista network quick to timeout CMoya Vista performance & maintenance 3 12 Feb 2008