?
Solved

Script to monitor a task and restart

Posted on 2005-03-02
9
Medium Priority
?
170 Views
Last Modified: 2010-04-14
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
Comment
Question by:rjohnsonjr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 1000 total points
ID: 13441419
You won't need a script for that, the following batch file will do:

@echo off
:respawn
start /wait someprogram.exe
goto respawn
0
 
LVL 6

Author Comment

by:rjohnsonjr
ID: 13441540
but that is not as good a service that would monitor it.  

I will try this though.

Randy
0
 
LVL 86

Expert Comment

by:jkr
ID: 13441639
>> 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 6

Author Comment

by:rjohnsonjr
ID: 13441871
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
 
LVL 6

Author Comment

by:rjohnsonjr
ID: 13442246
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
 
LVL 86

Expert Comment

by:jkr
ID: 13442384
>>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
 
LVL 6

Author Comment

by:rjohnsonjr
ID: 13442476
for ( ;;) {

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

}


Do I put this in  a VBS Script file?


-Randy
0
 
LVL 19

Expert Comment

by:billmercer
ID: 13443205
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
 
LVL 17

Assisted Solution

by:Eagle6990
Eagle6990 earned 1000 total points
ID: 13446676
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Check out the latest tech news, community articles, and expert highlights in August's newsletter.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question