Skip to content

Instantly share code, notes, and snippets.

@prashanthrajagopal
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prashanthrajagopal/9171b93f5c17e3d74835 to your computer and use it in GitHub Desktop.
Save prashanthrajagopal/9171b93f5c17e3d74835 to your computer and use it in GitHub Desktop.
Batch Script to restart a process if not already running. It runs every 5 seconds
@echo off
:loop
REM Check if the process is already running
tasklist /fi "imagename eq %1" | find /i "%1" > nil
if errorlevel 1 (
REM If not start the process
goto :main
) else (
REM Else keep checking every 5 seconds whether it is alive
timeout /t 5
goto :loop
)
:main
if [%2] == [] (
start /wait %1
) else (
REM Use this if the process is to be run a s a different user
runas /profile /user:%2 "CMD /C %1"
)
goto :main
REM Usage example - start /B restart.bat notepad.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment