Can someone explain the logic behind this?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5

Thread: Can someone explain the logic behind this?

  1. #1
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Can someone explain the logic behind this?

    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.

  2. #2
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    3,962

    Re: Can someone explain the logic behind this?

    >.<

    Because that's how it's supposed to work.

    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.

  3. #3
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Can someone explain the logic behind this?

    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.

  4. #4
    Join Date
    Feb 2009
    Location
    Portland, OR
    Posts
    1,488

    Re: Can someone explain the logic behind this?

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

  5. #5
    Join Date
    Apr 1999
    Posts
    27,433

    Re: Can someone explain the logic behind this?

    Quote Originally Posted by ahmd View Post
    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.

    Regards,

    Paul McKenzie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center