/build/static/layout/Breadcrumb_cap_w.png

Scripting Problems

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.

0 Comments   [ + ] Show comments

Answers (1)

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
Posted by: dchristian 12 years ago
Red Belt
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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ