script or batch to stop- start windows service

G

Guest

1)Is it possible to write a script or batch file to the below

Begin

Stop the SampleWindows Service.
If SampleWindows service doesn’t stop gracefully,
kill the SOME.exe say Outlook.exe process/process tree and
kill the SampleWindows.exe process
and then
Start the SampleWindows service.

END.

2) is there a way to capture the return code of NET STOP/START command? in a
batch / script code?

thanks a lot in advance.
 
P

Pegasus \(MVP\)

kmsr said:
1)Is it possible to write a script or batch file to the below

Begin

Stop the SampleWindows Service.
If SampleWindows service doesn't stop gracefully,
kill the SOME.exe say Outlook.exe process/process tree and
kill the SampleWindows.exe process
and then
Start the SampleWindows service.

END.

2) is there a way to capture the return code of NET STOP/START command? in a
batch / script code?

thanks a lot in advance.

Try this:

@echo off
net stop "some service"
net start | find "some service" || pskill outlook & kill OtherProcess
net start "some service"

@echo off
net start "some service"
echo The return code was %ErrorLevel%
 
P

Pegasus \(MVP\)

kmsr said:
1)Is it possible to write a script or batch file to the below

Begin

Stop the SampleWindows Service.
If SampleWindows service doesn't stop gracefully,
kill the SOME.exe say Outlook.exe process/process tree and
kill the SampleWindows.exe process
and then
Start the SampleWindows service.

END.

2) is there a way to capture the return code of NET STOP/START command? in a
batch / script code?

thanks a lot in advance.

I forgot to say: You can get psexec.exe from www.sysinternals.com.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top