Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a batch file which uses taskkill to stop several services. The commands look like this:

taskkill /s \\myServer /f /fi "Services eq MyService"

The problem is that each command takes a really long time (around 1 minute). Since there are several such commands, the batch file is really slow.

Is there any way to speed up taskkill?

share|improve this question
add comment

3 Answers 3

Try using sc stop instead of killing the service. It's a preferred method.

http://technet.microsoft.com/en-us/library/cc742107(WS.10).aspx

share|improve this answer
    
A service will try going through a normal service stop procedure, which can take a little while, but is always safer than a hard process kill. A process kill should only be used when absolutely necessary. –  music2myear Sep 1 '11 at 22:09
    
OK but is sc any faster than taskkill? That was my real question. –  JoelFan Sep 2 '11 at 15:25
    
Sorry, didn't mean to ignore that aspect of the question, but I really can't say for sure. I was hoping you'd test it and let us know. The answer to that question might be service specific. Nixphoe's method might help as long as there isn't a specific order that the services must be stopped. –  pk. Sep 6 '11 at 13:06
add comment

In addition to what @pk said, if you must use taskkill, you could create one bat file for each task to kill, then create a bat file to call each batch file.

Would still be slow for each taskkill to finish, but they would run at the same time, speeding up your full script.

Should look something like this:

cmd /c c:\bat\killbatch1.bat
cmd /c c:\bat\killbatch2.bat
cmd /c c:\bat\killbatch3.bat
share|improve this answer
add comment

I tried switching to sc but it was also very slow. There is some underlying issue (possibly networking related?) but I haven't been able to find it.

I ended up moving the service stopping code to a .vbs script using WMI using the info here.

share|improve this answer
    
Don't forget to "accept" your answers. It'll help with that 45% accept rate :) –  Nixphoe Sep 16 '11 at 12:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.