Link to home
Start Free TrialLog in
Avatar of Randy Johnson
Randy JohnsonFlag for United States of America

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
ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Randy Johnson

ASKER

but that is not as good a service that would monitor it.  

I will try this though.

Randy
>> 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.
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 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
>>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...
for ( ;;) {

PROCESS_INFORMATION pi;
CreateProcess ( "notepad.exe", ...,  &pi);
WaitForSingleObject ( pi.hProcess, INFINITE);

}


Do I put this in  a VBS Script file?


-Randy
Avatar of billmercer
billmercer

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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial