Difference between software initiated shutdown and using the power button?
Solution 1:
It's the same.
Like you said, you can force a shutdown by holding down the power button for longer (approximately 4 seconds), but this is literally cutting the power. An ACPI-initiated shutdown is the same as one you call through software. Both ways, all applications running on the machine have to be informed of the pending shutdown, (possibly abort it, depending on the version of Windows), and close themselves and any files they have open gracefully. That all takes time.
Basically, what makes the magic happen in either case is a call to the ExitWindowsEx
function, which is part of the Windows API used by programmers.* If you specify the EWX_POWEROFF
flag, the system is shut down and the power is turned off. It is also possible to call that function with the EWX_FORCE
flag, which will do just what it sounds like—force a shutdown without giving running applications the ability to delay or cancel it. If you do that, shutdown will likely happen faster but it will not be a completely "clean" shutdown and is therefore dangerous.
The difference in behavior that you're seeing is probably due to way that the software shutdown is initiated. For example, when you execute shutdown.exe
, you can indicate a timeout value for when the shutdown request should be initiated. During this period, the pending shutdown can be cancelled by running shutdown.exe
again with the /a
flag (to abort a pending shutdown). 60 seconds is a pretty common value for this timeout period.
The rest of the difference is probably just perceptual.
* The fact that Windows is a multi-user operating system can make things somewhat more complicated. But that's getting beyond the point here. Any other method of initiating a shutdown (e.g., InitiateSystemShutdown
) is going to behave similarly.
Solution 2:
When you press the power button, the system is sent an ACPI signal indicating that the power button has been pressed. What the system does in response to this signal is determined by the system's settings. For Windows, the system may be configured to shut down, go to sleep, or hibernate when the power button is pressed.
In any case, the operating system responds to the power button being pressed and reacts in essentially the same manner as if you instructed the system to shut down, sleep, or hibernate through the menus or programmatically.