Scripting – check if process or program is running and start it

Sometimes you have to have a program running for other programs to work. If this program does not run as a Windows service, use this script to check for program’s process name, and start it if it’s not running. Use your own process name instead of ‘calc.exe’ and you can take out the ‘wscript.echo’ line.
Then, run this script under Scheduled Tasks every 15 minutes or so. You may have to run the scheduled task with elevated privileges, or using a Local Administrator or Domain Administrator accounts.
===
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:” _
& “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
Set colProcesses = objWMIService.ExecQuery _
(“Select * from Win32_Process Where Name = ‘calc.exe'”)
If colProcesses.Count = 0 Then
Set WshShell = WScript.CreateObject(“WScript.Shell”)
Command = “%windir%\system32\calc.exe”
WshShell.Run Command
Else
Wscript.Echo “calc.exe is running.”
Set WshShell = WScript.CreateObject(“WScript.Shell”)
Command = “%windir%\system32\calc.exe”
WshShell.Run Command
WSCript.Quit
End If
WSCript.Quit

Leave a Reply

Your email address will not be published. Required fields are marked *