Randy Johnson
asked on
Script to monitor a task and restart
I am looking for a script/program that will monitor a program in the task manager and if it is not running start the program. It needs to run in the background as a service
The idea would be to set up the script or program to run as a service and check every few seconds to see if the program is exited and start it up again.
Thanks!
Randy
The idea would be to set up the script or program to run as a service and check every few seconds to see if the program is exited and start it up again.
Thanks!
Randy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>> but that is not as good a service that would monitor it.
Are you sure? A service would do the same and consume more resources.
Are you sure? A service would do the same and consume more resources.
ASKER
Well indeed that it would consume some more resources but I do not think they would be significant.
I think from it would be more secure for the service to monitor it rather than relying on a start / wait. That may indeed be the only solution
Randy
I think from it would be more secure for the service to monitor it rather than relying on a start / wait. That may indeed be the only solution
Randy
ASKER
I did what you said:
@echo off
:respawn
start /min /wait c:\windows\notepad.exe
goto respawn
I included the /min and it minized notepad not the dos window.
Is is possible to not show the dos window?
Randy
@echo off
:respawn
start /min /wait c:\windows\notepad.exe
goto respawn
I included the /min and it minized notepad not the dos window.
Is is possible to not show the dos window?
Randy
>>I think from it would be more secure for the service to monitor it rather than relying on a start / wait.
No. A service would also only perform a
for ( ;;) {
PROCESS_INFORMATION pi;
CreateProcess ( "notepad.exe", ..., &pi);
WaitForSingleObject ( pi.hProcess, INFINITE);
}
That's also what 'start /wait' does (hmm, I wrote the one or the other service :o)
>>Is is possible to not show the dos window?
Let me see if I can dig out something...
No. A service would also only perform a
for ( ;;) {
PROCESS_INFORMATION pi;
CreateProcess ( "notepad.exe", ..., &pi);
WaitForSingleObject ( pi.hProcess, INFINITE);
}
That's also what 'start /wait' does (hmm, I wrote the one or the other service :o)
>>Is is possible to not show the dos window?
Let me see if I can dig out something...
ASKER
for ( ;;) {
PROCESS_INFORMATION pi;
CreateProcess ( "notepad.exe", ..., &pi);
WaitForSingleObject ( pi.hProcess, INFINITE);
}
Do I put this in a VBS Script file?
-Randy
PROCESS_INFORMATION pi;
CreateProcess ( "notepad.exe", ..., &pi);
WaitForSingleObject ( pi.hProcess, INFINITE);
}
Do I put this in a VBS Script file?
-Randy
That's not VBScript, it's a snippet of C++ code.
I like to use AutoIt to do stuff like this. It's compact, free, and easier to use than VBScript.
http://www.hiddensoft.com
I like to use AutoIt to do stuff like this. It's compact, free, and easier to use than VBScript.
http://www.hiddensoft.com
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will try this though.
Randy