Solved

Batch File to Stop and Start a Service

Posted on 2009-05-11
5
1,063 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
[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
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
AutoHotkey is an excellent, free, open source programming/scripting language for Windows. It started out as a keyboard/mouse macros product, but has expanded into a robust language. This article provides an introduction to it, with links to addition…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

695 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