' Set up some constants
Const ForReading = 1
Const ForAppending = 8
' get the FSO open
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Process you are looking for
sProcess = "csrsc.exe"
' Build the date tag for the log file name
sDate = right("00" & cstr(month(date())),2) & right("00" & cstr(day(date())),2) & right("200" & cstr(year(date())),4) & right("00" & cstr(hour(time)),2) & right("00" & cstr(minute(time)),2) & right("00" & cstr(second(time)),2)
' Build the full log file name
sOutFileName = "C:\Temp\scan_log_" & sDate & ".txt"
' Open the file with containing all of the computers to scan (name or IP address)
Set objTextFile = objFSO.OpenTextFile ("C:\Temp\machineList.txt", ForReading)
' Create and open the file for logging
Set objTextFile_Write = objFSO.OpenTextFile(sOutFileName, ForAppending, True)
' Loop through the file containing machine names/IP addresses
Do Until objTextFile.AtEndOfStream
' get the machine name from the current row of the file
sMachine = objTextFile.Readline
' duh
Dim Process, sResponse, sWriteMe
' Default the test response
sResponse = "No"
' duh
ON ERROR RESUME NEXT
' Ping the machine to make sure it is on the network
Set WshShell = CreateObject("WScript.Shell")
bPing = Not CBool(WshShell.run("ping -n 1 " & sMachine, 0, True))
' only check for the process if the machine is on the network
If bPing = True Then
Set objWMI = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set cProcList = objWMI.ExecQuery ("Select * from Win32_Process Where Name = '" & sProcess & "'")
' if there are items in the collection ....
If cProcList.Count > 0 Then
' Found it!
sResponse = "Yes"
End If
Else
' Set the appropriate response
sResponse = "Not on network"
End If
' If there was an error ... Log it!
If err.number > 0 Then
sResponse = err.Description
End If
sWriteMe = sMachine & ": " & "Running " & sProcess & " - " & sResponse
objTextFile_Write.WriteLine(sWriteMe)
Loop