Example.bat
REM Example Script.bat (note I path to the .exe dir so it runs in its locat folder)
d:
cd \Directory\Or\EXE\Process
C:\myscripts\StartProc.vbs d:\Directory\To\EXE\Process\ ProcessName.exe start
StartStopProc.vbs
Option Explicit
'mReschke fo zabbix 2009-03-12
'Will start/stop a process
'Will only start 1 process, will not start if already started, no multiples
Dim ArgObj, strComputer, objWMIService, colProcesses, Process
Dim processPath, processName, processAction
Set ArgObj = WScript.Arguments
processPath = ArgObj(0) 'Command parameter: full path (no filename) to executable (with \ at end)
processName = ArgObj(1) 'Command parameter: file name (no fullpath) of executable
processAction = ArgObj(2) 'Command parameters (start or stop)
'Example Script.bat (note I path to the .exe dir so it runs in its locat folder)
'd:
'cd \Generator\bin
'd:\scripts\StartProc.vbs d:\Generator\bin\ Generator.exe start
If IsRunning = True Then
If processAction = "stop" Then
Call KillProcess
End IF
Else
If processAction = "start" then
Call StartProcess
End If
End If
Function IsRunning()
Dim processRunning
processRunning = false
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer& "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name='" & processName & "'")
For Each Process in colProcesses
If Process.Name = processName Then
processRunning = True
End If
Next
IsRunning = processRunning 'return processRunning (true or false)
End Function
Sub StartProcess()
'Start the Process
Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "" & processPath & processName & ""
Set oShell = Nothing
End Sub
Sub KillProcess()
strComputer = "."
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer& "\root\cimv2")
Set colProcesses = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name='" & processName & "'")
For Each Process in colProcesses
If Process.Name = processName Then
Process.Terminate()
End If
next
End Sub