Friday, March 08, 2013 10:16 AM
I have a requirement to stop a particular service before rebooting the server. I have tried shutdown script in GPO but it doesn't work when rebooting using command shutdown -r -t 0.
Any suggestion please.
Friday, March 08, 2013 10:42 AM
See sc command.
sc stop servicename
For Help Type
Friday, March 08, 2013 11:57 AM
Thanks Dave for your reply.
I use command "net stop servicename" to stop the service, But I want the specific service to be stopped automatically whenever the server is being restarted interactively or non-interactively (automated task or wsus).
Shutdown script in GPO works only when server "shutdown" however it is not working if we are restarting using command shutdown -r -t 0.
Friday, March 08, 2013 12:47 PM
As far as I know you'll need to write a program to receive shutdown messages from Windows, pause the shutdown, shutdown your service, and resume shutdown.
The rules about blocking shutdown are windows version specific.
Friday, March 08, 2013 1:40 PM
David is correct. The problem you are facing is that the shutdown scritp is executed after the shutdown has been processed by all processes. Console commands are not allowed once WOW has been terminated because they need a session.
I have never tried this but WMI might be able to do this but not WMIC. Only the WinMgmts object would be able to operate during a shutdown.
Note that a shutdown script will force a shutdown to freeze. Do not use message boxes in a shutdown script.
Friday, March 08, 2013 5:05 PM
Why not just change the way you shut down the Server? You could use powershell and just make a script with something like:
Get-Service -ComputerName targetserver -Name TargetService | stop-service Restart-Computer -ComputerName TargetServer
It seems like that would be way easier than the other options.