script or batch to stop- start windows service

  • Thread starter Thread starter Guest
  • Start date Start date
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.
 
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%
 
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.
 
Back
Top