Reputation: 295
I have a script that executes remotely to see if a program is running. It works fine but I need it to check for several programs on several servers and I don't want to re-write it. I'm trying to see if I can call the function within the vbscript via command line so that I can use 1 script and change the arguments at the command line.
Function IsProcessRunning(strComputer, strProcess)
Dim Process, strObject
IsProcessRunning = 0
strObject = "winmgmts://" & strComputer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase( Process.name ) = UCase( strProcess ) Then
IsProcessRunning = 1
If IsProcessRunning = 1 Then
WScript.echo 1 & ": " & strProcess & " is currently running on " & strComputer
End If
Exit Function
End If
Next
WScript.echo 0 & ": " & strProcess " is NOT running on " & strComputer
End Function
What I'm hoping for is to be able to run this via cmd like: run.vbs IsprocessRunning Server3 Program2.exe
Upvotes: 2
Views: 2072
Reputation: 12612
UPDATE
Why not to use WMIC
? E. g. type in command line:
wmic /node:server1 process where name='explorer.exe' get processid
to get all launched explorers process ID on server1.
SOURCE
Use WScript.Arguments
property:
IsProcessRunning WScript.Arguments(0), WScript.Arguments(1)
Function IsProcessRunning(strComputer, strProcess)
Dim Process, strObject
IsProcessRunning = 0
strObject = "winmgmts://" & strComputer
For Each Process in GetObject( strObject ).InstancesOf( "win32_process" )
If UCase(Process.name) = UCase(strProcess) Then
IsProcessRunning = 1
WScript.echo 1 & ": " & strProcess & " is currently running on " & strComputer
Exit Function
End If
Next
WScript.echo 0 & ": " & strProcess & " is NOT running on " & strComputer
End Function
Better to add some check if the appropriate command line arguments provided to script.
Upvotes: 2