I was using InitiateSystemShutdownEx() to reboot the system (I asked about it in a separate thread, but this question is not related to it.) On Windows XP, if a workstation is locked that API returns FALSE and Getlasterror returns ERROR_MACHINE_LOCKED, which means "The machine is locked and cannot be shut down without the force option." The function succeeds if I set the bForceAppsClosed parameter to TRUE to "force" the operation, but in that case any unsaved data will be lost.
Can someone explain for me, what is the reason to enforce such behavior?
PS. The workstation may be locked automatically if someone enables password protection in a screen saver.
InitiateSystemShutdownEx() is not a guarantee to success, it can fail for any number of reasons. You cannot use this function as a guaranteed 'safe reboot'. It's use in unattended code (you're using a service) is questionable (like I said before).
You're requesting the system to shut down (typically in a few minutes to give users time to clean up, if they don't, tough for them). This sort of action should typically only happen as part of the system admin performing some actions and requiring the reboot.
There are several reasons why the request can be denied, the machine being locked is one, the machine having critical operations pending is another (there's more).
The forceappsclosed flag allows you to override some (not all) of those reasons, but that also means users have less chance to clean up.
Your call causes the message WM_QUERYENDSESSION to be sent to any application running on that server. If there is any application which returns false to that message the shutdown process was stopped.
I assume that a locked screen saver would return false to the message cause applications could not ask for saving while the screen saver is locking the screen.
Guys, my question was not why a shut-down can fail, but why was it supposed to fail by definition on a locked workstation on Windows XP and Windows Server 2003 only. It just doestn't make sense to me...
Guys, my question was not why a shut-down can fail, but why was it supposed to fail by definition on a locked workstation on Windows XP and Windows Server 2003 only. It just doestn't make sense to me...
Ask Microsoft -- it's their rules and their OS.
If the documentation from Microsoft clearly states this is the situation, the engineers must have a reason for this. It may not make sense to you, but it had to make sense for MS, else they wouldn't clearly state it in their docs that this is the behaviour.
Bookmarks