Announcement

Collapse
No announcement yet.

VBS: Check for file existence on a set of remote comuters.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • VBS: Check for file existence on a set of remote comuters.

    Code:
    '********************************************************************
    '*  Author: Guy Teverovsky
    '*
    '*  The script enumerates the computer objects in a given OU,
    '*  checks whether a computer is reachable over the network,
    '*  and if yes, verifies the existence of a given file on the 
    '*  remote computer.
    '*  Can be used for checking "flag" files like c:\NotWorm or 
    '*  dll versions. I used it to verify that users got a specific update 
    '*  installed.   
    '* 
    '********************************************************************
    
    strOUDN = "OU=Workstations,OU=Clients,DC=test,DC=net"
    
    Set objRootDSE = GetObject("LDAP://RootDSE")
    strClientsPath = "LDAP://" & strOUDN 
    Set objClientsContainer = GetObject(strClientsPath)
    objClientsContainer.filter=array("computer") 
    
    'The file we want to check
    strSearchFile = "c$\Program Files\Test\Test.exe"
    
    For Each objClient In objClientsContainer
    	arClient= split(objClient.Name,"=")
    	strClient = arClient(1)
    	If IsPingable(strClient) Then
    			Set objFSO = CreateObject("Scripting.FileSystemObject")
    			strSearchFileUNC = "\\" & strClient & "\" & strSearchFile
    			If objFSO.FileExists(strSearchFileUNC) Then
    				strSearchFileVer =  objFSO.GetFileVersion(strSearchFileUNC)
    				If strSearchFileVer <> "" Then
    					Wscript.Echo(strSearchFileVer)
    				End If
    			Else 
    				WScript.Echo("Computer " & strClient & " does not have the file in question")
    			End If
    	Else
    			WScript.Echo("The client is not reachable...")
    	End If
    		
    Next
    
    '********************************************************************
    '* Function IsPingable(strHost)
    '*								
    '*	Returns True or False based on the output from ping.exe	
    '********************************************************************
    Function IsPingable(strHost)
    	Set objShell = WScript.CreateObject("WScript.Shell")
    	Set objExecObject = objShell.Exec("cmd /c ping.exe -n 3 -w 1000 " & strHost)
    	Do While Not objExecObject.StdOut.AtEndOfStream
    		strText = objExecObject.StdOut.ReadLine()
    		If Instr(strText, "Reply") > 0 Then
    	        		'Wscript.Echo "Reply received."
    	        		IsPingable = True
    			Exit Do
    		End If
    	Loop
    	If (IsPingable <> True) Then
    		IsPingable = False
    	End If
    End Function
    Guy Teverovsky
    "Smith & Wesson - the original point and click interface"
Working...
X