ghacks has post on Application Monitor today which is simple program to keep applications running. It watches them and restarts if they are closed for any reason.
Since that is one of those small tasks that I prefer to code myself instead of having to use one more software title I made draft in AutoIt.
Step by step.
- Let’s define what we want to keep running and time between checks.
- Checking if that is real file.
If Not FileExists($path) Then Exit
- Since Windows identifies processes by executable name we need to get it out of path (and check if it is executable at all).
$executable=StringRegExp($path, ".*\\(.*\.exe)",1) If @error Then Exit $executable=$executable
This code searches by regular expression that in human words means “everything after last \ if it ends with .exe”. Failure is detected as non-zero @error value. StringRegExp returns array but we only need single match so we take that from  position. Checking for errors is important here because working with non-array variable as with array is one of few things that instantly crash AutoIt. 4. Check and loop. Sleep takes milliseconds so we multiply by 1000.
While 1 If Not ProcessExists($executable) Then Run($path) Sleep($tick*1000) WEnd
Combining to single file : https://www.rarst.net/script/keeprunning.au3
There are obviously plenty of ways to enhance this like adding nice interface or reading list of applications to watch. But that depends on personal tastes. That’s power of scripting for yourself - you get what you need. :)
By the way I wanted to ask for some feedback on AutoIt posts. This was defined as secondary theme to blog from the beginning and I get constant search traffic on it. But I have some doubts.
Do you find it interesting? Or boring? Or have some task you want to script but scared to start? Tell me in the comments. :)