Solved

Batch as a service auto Restart

Posted on 2009-04-09
6
1,115 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now