Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Visual C++ 2010 Express - Force Logoff  (Read 3637 times)

0 Members and 1 Guest are viewing this topic.

Fleexy

    Topic Starter


    Intermediate

  • OW NEXT TIME I SHOULD TURN IT OFF BEFORE SERVICING
  • Thanked: 2
    • Yes
    • Yes
  • Experience: Experienced
  • OS: Windows XP
Visual C++ 2010 Express - Force Logoff
« on: February 15, 2011, 01:23:07 PM »
Would someone please tell me how to force the current user to logoff?  I'm using Visual C++ 2010.
I love .NET!

gluxon

  • Guest
Re: Visual C++ 2010 Express - Force Logoff
« Reply #1 on: February 16, 2011, 05:11:20 PM »
The ExitWindowsEx() function should do it. Make sure you include windows.h :)

For dwReason, you need to enter a System Shutdown Reason code. The full list is over here. So, for example, this should log off the user with "Application Issue" as the reason. (WARNING: UNTESTED)
Code: [Select]
#include <windows.h>

int main() {
    ExitWindowsEx(EWX_LOGOFF, SHTDN_REASON_MAJOR_APPLICATION);
}