Solved

Batch as a service auto Restart

Posted on 2009-04-09
6
1,116 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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Editing Powershell script to resolve DNS from HashTable ? 7 58
Combine DSQuery result into loop script 6 58
x-bar in Google Sheets 2 52
Problem to App 4 79
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.

786 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