Shutdown, logout, restart function: exitwindowsex

Source: Internet
Author: User

Overview The exitwindowsex () function is used to exit, restart, or log out of the system. Edit this section Function prototype Bool exitwindowsex (uint uflags, // disable the DWORD dwreserved parameter // retain the system, usually 0 ); Edit this section Parameters Uflags Specifies the type to close. This parameter must have a combination of the following values: Ewx_force Force terminate the process. When this flag is set, Windows does not send messages of wm_queryendsession and wm_endsession to Program . This may cause the application to lose data. Therefore, you should only use this flag in emergencies. Ewx_logoff Close all processes and log out of the user. Ewx_poweroff Turn off the system and turn off the power. The system must support power failure. Windows requirements: in Windows NT, the calling process must have the se_shutdown_name privilege. In Windows 9x: it can be called directly. Ewx_reboot Shut down the system and restart the system. Windows requirements: in Windows NT: The Calling process must have the se_shutdown_name privilege. In Windows 9x: it can be called directly. Ewx_shutdown Shut down the system and safely shut down the power supply. All file buffers have been refreshed to the disk, and all running processes have stopped. Windows requirements: in Windows NT: The Calling process must have the se_shutdown_name privilege. In Windows 9x: it can be called directly. Dwreserved System reserved. this parameter is ignored. Generally, 0 is used. If the function is successful, the return value is non-zero. If the function fails, the return value is zero. For more error information, call the getlasterror function. Edit this section Remarks After the exitwindowsex function is returned, the function is disabled. Close or log out. During shutdown or login operations, the application responds to the shutdown request within the specific amount of time allowed for shutdown. If the time expires, Windows displays a dialog box that allows you to forcibly close the application: Close, retry, or cancel the shutdown request. If a value specified by ewx_force exists, Windows closes the application without displaying this dialog box. In Windows NT: to shut down or restart the system, the calling process must use the adjusttokenprivileges function to grant the se_shutdown_name privilege. Windows
95: security privileges, not supported or required. Edit this section Example Windows 9x: exitwindowsex (ewx_shutdown, 0); // disable the system exitwindowsex (ewx_reboot, 0); // restart the system Windows NT/2000/XP: The following function is provided if it is not MFC, add the following statement before the function # define bool int # define true 1 # define false 0 if yes, add bool systemshutdown () {handle htoken; token_privileges tkp;/* openprocesstoken () this function is used to open the access token getcurrentprocess () of a process. The function is used to obtain the handle of this process */If (! Openprocesstoken (getcurrentprocess (), Token | token_query, & htoken) return false; // lookupprivilegevalue () is used to modify the process permission lookupprivilegevalue (null, se_shutdown_name, & tkp. privileges [0]. luid); tkp. privilegecount = 1; // One privilege to set is assigned to this process Privilege tkp. privileges [0]. attributes = se_privilege_enabled; // adjusttokenprivileges () is used to notify Windows NT of the right to modify the process adjusttokenprivileges (htoken, false, & tkp, 0, (ptoken_privileges) null, 0); If (getlasterror ()! = Error_success) // failure return false; If (! Exitwindowsex (ewx_poweroff | ewx_force, 0) // set the parameter here. Forcibly exit windows (ewx_force ). Return false; return true ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.