Solved

Batch File to Stop and Start a Service

Posted on 2009-05-11
5
1,056 Views
Last Modified: 2012-05-06
Experts

I have a batch file that will need to be scheduled at 5:00 in the morning. This will stop and start a particular service.
When I run the command the service stops but will not start again. I have narrowed teh problem down to teh Log On option within the properties of the service.
Rather than using Local System account I am using Log On As with a User ID and password.
How can I fit this into the batch file without changing it back to Local System?
My command line is:

Net Stop "Service"
Net Start "Service"

Cheers
0
Comment
Question by:shconsultancy
5 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 24355566
Try setting the scheduled task that runs the batch file needs to be run as the same user.
0
 
LVL 4

Accepted Solution

by:
TG_Tech earned 250 total points
ID: 24356035
NET LOGON username password
0
 
LVL 6

Expert Comment

by:question
ID: 24361261
well... use the command Net Stop "Service" && Net Start "Service"
often.. the command does not wait for the first step to complete before proceeding to next step hence altering it in format && it waits for first command to complete before moving further.

-?
0
 
LVL 7

Expert Comment

by:johnnash1180
ID: 24375642
I believe that you are stopping the service and then immediately starting the service. It may take some time to stop the service. At that time service will be in stopping state. When the service is in stopping state, you cannot start it. Instead, you can wait for some time and then start the service. You can add delay by using "ping localhost -n <time in seconds>" command.

The code will be as follows:

net stop service
ping localhost -n 10
net start service

Change the 10 value to a suitable value.

The best method is getting status of service by sc command. To get the status of a service, you can use 'sc query <service name> | find "STATE" ' command.

John Nash
0
 
LVL 1

Author Closing Comment

by:shconsultancy
ID: 31580155
I tried that initially but I got the syntax wrong!!! Thanks for teh correction, it works just fine now.
0

Featured Post

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.

Question has a verified solution.

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

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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