I am working on a batch script that will stop a service, delete some files, copy some new files, and then start the service. I've created the batch file locally on a machine and ran it without problems. When I run the same batch through KACE it seems to get stuck.

I use an "sc stop" command on the service to get it to stop. On some machines the service is already stopped and set to disabled. This means the sc stop command will not work which is ok because I still want to get the new files on the machine.

After the sc stop, I threw in a ping 127.0.0.1 /n 15. This gives the service time to actually stop before it tried to delete and copy files. I then go on to delete a couple files with the "Del" command and copy the files to the directory using an "xcopy" command.

I do another ping 127.0.0.1 /n 15 to give the file transfers time to finish, and then turn the service back on using an "sc start" command.

Like I said, this works perfect if I'm running the .bat file locally on the machine whether the service is on or set to disabled.

When I run it through KACE on a machine with the service disabled, the batch file seems to stop when the sc stop command doesn't work. Why does it do this with KACE but not locally?

By the way, I'm not using the "Start a service..." and "Stop a service..." tasks in KACE because they don't wait for the service to actually stop before trying to delete and transfer files or finish before trying to start again.

Any help would be greatly appreciated.
Answer Summary:
http://stackoverflow.com/questions/3325081/how-to-check-if-a-service-is-running-via-batch-file-and-start-it-if-it-is-not-r
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

3
What if you check to see if the service is running first before you try stopping it?

I think this post will point you in the right direction;
http://stackoverflow.com/questions/3325081/how-to-check-if-a-service-is-running-via-batch-file-and-start-it-if-it-is-not-r
Answered 03/30/2012 by: dchristian
Red Belt

Please log in to comment
Answer this question or Comment on this question for clarity