|
Answer» Hi Guys and Gals,
I'd like to write a batch file that checks if an application or process is RUNNING on a computer and, if not, start the application. I will be calling the batch file in a scheduled task.
Cheers,
GavThis LITTLE SNIPPET should run on most Windows machines:
Code: [SELECT]strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colProcesses = objWMIService.ExecQuery _ ("Select * from Win32_Process Where Name = 'Notepad.exe'") If colProcesses.Count = 0 Then Set objShell = CreateObject("Wscript.Shell") objShell.Run "notepad.exe" End If
Save script with a vbs extension. You can run DIRECTLY from the command line as cscript scriptname.vbs or call it from your scheduled task with call cscript scriptname.vbs.
Note: As written, the script checks for the notepad program. Change as needed.
8-)Or with a batch file, you can use: Code: [Select]set Application=notepad.exe tasklist|findstr /i "%Application%" >NUL&if ERRORLEVEL 1 start %Application%And just change the Application= to the application you are checking for.Thanks Guys
|