Solved

Batch as a service auto Restart

Posted on 2009-04-09
6
1,118 Views
Last Modified: 2013-12-26
I need to setup a batch file as a service. The batch is set to run its task sleep for 20 seconds then run the task again. i need to be able to set this as a service that starts when the server starts. Runs without a user having to login to the server, and if someone logs in and closes the batch file it automatically restarts. I have seen a few places about setting it as a service which i have done however i cant get it to start the script again if i close the batch file.
0
Comment
Question by:purpleoak
  • 4
  • 2
6 Comments
 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 24108649
When you run a batch script as a service, it invokes CMD.EXE, which will show up in your process list. As with any service, if you end the process, it will not automatically restart itself, unless it is restarted by another process.

What you need to do is go into the properties of that service (SERVICES.MSC) and in the tab at the top labeled "Recovery", select "Restart the service" for 1st, 2nd, and subsequent failures.
tmppic.jpg
0
 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 24133856
Any news?
0
 
LVL 2

Author Comment

by:purpleoak
ID: 24159178
Restarting the computer isnt really all that helpful as the server needs to be on all the time. This script checks certain tasks and copies files from a to b. sorry
0
Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 24159741
NO, you need to select the drop down box. There is an option to restart the service, as I indicated in my notes. Here is another screenshot showing all the options.
ss.JPG
0
 
LVL 2

Author Comment

by:purpleoak
ID: 24165709
It doesnt restart the script if i close it. I have tried this but it didnt seam to restart it, even if i set restart after 1 min, 1 hour etc.
0
 
LVL 6

Accepted Solution

by:
Justin_W_Chandler earned 500 total points
ID: 24167306
If someone with administrator priviledges logs in, they will have the ability to close or stop ANY service. If the problem you're having is people stopping the service (or closing the service in task manager), you can't do anything to circumvent that. Preventing that sort of interaction is part of good security administration.

There is really only three ways you can help prevent this, however. One is to create a second service that monitors the first. If the first is closed, it would restart it. Frankly, if the user is savy enough about it, this trick may not work because they will simply close both services.

The second involves a little bit trickier method -- create a dependency for winlogon under this service. Then, if they close that service the machine will log them off. After closing the service (resulting in them being logged off) a couple of times, they'll get the idea and leave it alone. AGAIN, however, with administrator privileges, they can simply remove the dependency and then close the service.

The third, which is probably the most effective -- is to create a service on another machine that people haven't access too. This service would periodically poll any machines that are supposed to have that service running, and restart it if necessary.

My friend, what you need to do is implement an appropriate security model that will prevent the users' ability to close the application. I know this is not the answer you were hoping for but that's as simple as it gets.

Justin Chandler
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

808 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