none
To stop a service automatically when restarting the server

    Question

  • 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:16 AM

Answers

  • 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.


    David Candy

    Friday, March 08, 2013 12:47 PM

All replies

  • See sc command.

    sc stop servicename

    For Help Type

    sc /?


    David Candy

    Friday, March 08, 2013 10:42 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 11:57 AM
  • 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.


    David Candy

    Friday, March 08, 2013 12:47 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 1:40 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.
    Friday, March 08, 2013 5:05 PM