8

Is there a tool that constantly checks, if another process is running, and if not, starts it? For Windows 7-10.

I have a background process running, a piece of free software I need. Even though it works great most of the time, sometimes it just crashes and disappears without further notice. Just restarting this software would solve my issue.

4 Answers 4

12

Using information from this question on Stack Overflow, you could create a .bat file like so (I've used Powerpoint as an example):

tasklist /FI "IMAGENAME eq POWERPNT.EXE" 2>NUL | find /I /N "POWERPNT.EXE">NUL
if NOT "%ERRORLEVEL%" == "0" start "" "C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE"

You could then either create a scheduled task to run this every minute or however long you can go without the process running

Alternatively, you could launch the application in an infinite loop:

@echo off
:1
"C:\Program Files\Microsoft Office\root\Office16\POWERPNT.EXE"
goto :1

This would reopen the program as soon as it's closed.

1
  • 1
    Your second option worked perfectly for my purposes: every now and then my torrent program crashes as it runs out of memory. This keeps it running like a hot-damn!
    – jeranon
    Nov 24, 2018 at 0:25
5

This is one of the things that you can do with AutoIt.

Create a small script that performs a check periodically. Something as simple as...

While True  
  If (ProcessExists("prog.exe") = 0) Then  
    Run("prog.exe")  
  EndIf  
  Sleep(1000)  
Wend

...or even...

While True  
  RunWait("prog.exe")  
Wend

...or more complex if you wish.

The script can be compiled to an exe and run quietly in the background.

0

You can use this PowerShell code on Windows:

(Get-Process).ProcessName | %{ if ($_ -imatch 'NOTEPAD') { Write-Host $_ 'is running' } }
0

I liked the answer from @Jonno, but it didn't work for me. So I created my own that is generic and can be reused. (Improvements are possible.)

  1. First argument is the process name (FIND will fail if you include .exe on the FIND command so this argument should NOT have .exe at the end, and the CMD assumes that it needs to restart a .EXE).
  2. Second argument is the path to the .EXE in case restart is needed. If the EXE is on the PATH, then you can drop the second argument.
SET SEARCH_FILE=search-%RANDOM%.log
TASKLIST /FI "IMAGENAME eq %~1.exe" 1>%SEARCH_FILE%
FIND /I /N "%~1" %SEARCH_FILE% >NUL
IF NOT "%ERRORLEVEL%" == "0" ( start /D "%~2" %1.exe )
DEL %SEARCH_FILE%

This takes into account arguments with or without "" as input.
Also, I was running this in multiple scheduled tasks on Task Scheduler and the TASKLIST was going to a single file (search.log), so I updated that so that the output is into a random file that is deleted afterwards.

Add a New Task in Windows Task Scheduler that runs cmd.exe with arguments /C <name_of_the_cmd_file> and start in the location where you saved this CMD (e.g. RestartProcess.cmd).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .