Thread: Information: Exiting Windows

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    387

    Post Information: Exiting Windows

    This may come to a shock to most of you, but the function to exit windows is.. YES, ExitWindows()

    Code:
    The ExitWindows function logs the current user off. 
    
    BOOL ExitWindows(
    
        DWORD dwReserved,	// reserved 
        UINT uReserved 	// reserved 
       );
    There is an ExitWindowsEx() function too.

    Code:
    The ExitWindowsEx function either logs off, shuts down, or shuts down and restarts the system. 
    
    BOOL ExitWindowsEx(
    
        UINT uFlags,	// shutdown operation
        DWORD dwReserved 	// reserved
       );
    the flags are:

    EWX_FORCE Forces processes to terminate. When this flag is set, Windows does not send the messages WM_QUERYENDSESSION and WM_ENDSESSION to the applications currently running in the system. This can cause the applications to lose data. Therefore, you should only use this flag in an emergency.

    EWX_LOGOFF Shuts down all processes running in the security context of the process that called the ExitWindowsEx function. Then it logs the user off.

    EWX_POWEROFF Shuts down the system and turns off the power. The system must support the power-off feature.Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.

    EWX_REBOOT Shuts down the system and then restarts the system. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.

    EWX_SHUTDOWN Shuts down the system to a point at which it is safe to turn off the power. All file buffers have been flushed to disk, and all running processes have stopped. Windows NT: The calling process must have the SE_SHUTDOWN_NAME privilege. For more information, see the following Remarks section. Windows 95: Security privileges are not supported or required.
    Hope that helps you, (none of you probly cared, but.. OH WELL!)

    [EDIT]Tried by best to make the flags readable[/EDIT]
    Last edited by Okiesmokie; 05-12-2002 at 09:30 AM.
    "There are three kinds of people in the world...
    Those that can count and those that can't."

  2. #2
    Registered User Xei's Avatar
    Join Date
    May 2002
    Posts
    719

    Heres source for Windows NT/2000/XP Shutdown

    Here is the source code to shut down the computer for Windows NT/2000/XP

    Code:
    #include "windows.h"
    #include "iostream.h"
    
    
    
    
    
    
    int main(int argc, char* argv[])
    {
    	TOKEN_PRIVILEGES tkp;
    	HANDLE hToken;
    	OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,&hToken); //We now have a Token for this Process.
    	//Now we must find the LUID ###'s for Shutting down the computer in Windows NT.
    	LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid); //Should now have the LUID Stored in our Privilege.
    	//Must set the privilege count.
    	tkp.PrivilegeCount = 1; //We are only setting one privilege for now.
    	tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; //Set this Privilege to Enabled. Otherwise it would disable it.
    	AdjustTokenPrivileges(hToken,FALSE,&tkp,0,NULL,0);
    	if (GetLastError() != ERROR_SUCCESS)
    	{
    		cout<<"Failed To Set Privileges";
    	}
    	ExitWindowsEx(EWX_SHUTDOWN | EWX_POWEROFF, NULL);
    	if (GetLastError() != ERROR_SUCCESS)
    	{
    		cout<<"Failed to shut down computer using forced attributes.";
    	}
    return 0;
    }
    The attributes are not forced, but you can add EWX_FORCE constant to force the shutdown of applications.
    Last edited by Xei; 05-12-2002 at 09:42 AM.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    387
    Yep, see you are using the ExitWindowsEx() function
    "There are three kinds of people in the world...
    Those that can count and those that can't."

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Windows Rant followed by installation question
    By confuted in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 06-21-2003, 04:42 PM
  3. Codec Bitrates?
    By gvector1 in forum C# Programming
    Replies: 2
    Last Post: 06-16-2003, 08:39 AM
  4. How come this only works in Windows nt/2000?
    By Unregistered in forum Windows Programming
    Replies: 1
    Last Post: 08-30-2002, 06:54 PM