Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

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
0
rjohnsonjr
Asked:
rjohnsonjr
2 Solutions
 
jkrCommented:
You won't need a script for that, the following batch file will do:

@echo off
:respawn
start /wait someprogram.exe
goto respawn
0
 
rjohnsonjrAuthor Commented:
but that is not as good a service that would monitor it.  

I will try this though.

Randy
0
 
jkrCommented:
>> 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.
0
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
rjohnsonjrAuthor Commented:
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
0
 
rjohnsonjrAuthor Commented:
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
0
 
jkrCommented:
>>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...
0
 
rjohnsonjrAuthor Commented:
for ( ;;) {

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

}


Do I put this in  a VBS Script file?


-Randy
0
 
billmercerCommented:
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
0
 
Eagle6990Commented:
If you want to stick with the batch file idea, I would download CMDOW and use it instead of the normal command prompt.  You can get this program to run completely hidden if you like:
http://www.commandline.co.uk/cmdow/index.html

Save CMDOW in %systemroot%\system32 and then put this in the beginning of your batch file:

cmdow @ /HID

It will run it completely hidden but still processing your script.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now