[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Batch File to Stop and Start a Service

Posted on 2009-05-11
5
Medium Priority
?
1,078 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 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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