In response to the AI answer, when I explicitly select 'Shutdown' from the Start menu, it should not be going to Sleep under any circumstances. Also, when I did my testing with the Power button and Lid closing, I had explicitly set the Power Option to do a shutdown. And when the system comes back up on booting, all the windows I had opened previously are all gone as would be expected for a full shutdown. Only the services are being suspended. All launched applications are gone on booting the system up. I have tested this on 4 laptops and 1 Desktop (minus the lid closing test for the Desktop for obvious reasons), and all tests show the same behavior. The behavior is wrong, but at least it is consistent.
Windows 11 (and 10) shutdown producing standby event instead of preshutdown
Hi,
I am writing a windows service that needs to listen for shutdown/restart/sleep/hibernate events on Windows client (Windows 10, 11) and server (2016, 2019) OS systems and notify an external server before the system goes down. The service is working fine. It gets the SERVICE_CONTROL_PRESHUTDOWN and PBT_APMSUSPEND events. But for some reason, for the client OSes, when I shutdown the system using the start menu (or by pressing the power button or closing the lid, when they are configured to shut the system down), the service gets the PBT_APMSUSPEND event and not the SERVICE_CONTROL_PRESHUTDOWN event. Furthermore, when the system is booted up after that shutdown, the service is still running even though the service is set up to be 'Manually' started - which is the behavior one would expect if it had been suspended. So it is internally consistent, but producing the wrong event.
When the system is shutdown from the command-line (shutdown /s /t 0), it correctly produces the SERVICE_CONTROL_PRESHUTDOWN event. I am surprised by the fact that the different ways of triggering a shutdown are going down different code paths. And the service is not started on booting the system up again, as would be expected for a service that is configured to be started 'Manually'.
When the systems are rebooted/restarted (whether from the start menu or from the commandline 'shutdown /r /t 0'), it correctly produces the SERVICE_CONTROL_PRESHUTDOWN event.
Note that on a Windows 2016 and a Windows 2019 server, the shutdown from the start menu (and the power button, when configured for shutdown) is correctly producing the SERVICE_CONTROL_PRESHUTDOWN event. Since these OSes are not getting any updates anymore, I am wondering if this is a regression that has been introduced in the shutdown behavior in one of the more recent updates.
I will be testing with Windows Server 2022 as well and will post my findings here. Any help is much appreciated.
Windows development | Windows API - Win32
2 answers
Sort by: Most helpful
-
-
RLWA32 50,836 Reputation points2025-11-08T08:02:41.8133333+00:00 Make sure that Fast Startup is disabled on the client systems. When it is enabled the system does not perform an actual shutdown. Users are logged off, their sessions are terminated and then the system enters a hibernation state. Windows services are not terminated in this state and when the system is "restarted" the system state, including Windows services, are restored.