Implementing a computer restart

Source: Internet
Author: User

1. New Project
2. Add 3 control button IDs of Idc_btclose Idc_btreset idc_btlogout respectively "Turn Off computer", "Restart", "Log Off Computer"
3. Set permissions to implement shutdown in OnInitDialog

Static HANDLE htoken;static token_privileges tp;static LUID luid;openprocesstoken (getcurrentprocess (), TOKEN_ADJUST_ privileges| Token_query,&htoken); Lookupprivilegevalue (NULL,SE_SHUTDOWN_NAME,&LUID); tp. Privilegecount = 1;tp. Privileges[0]. Luid = Luid;tp. Privileges[0]. Attributes = se_privilege_enabled; AdjustTokenPrivileges (Htoken,false,&tp,sizeof (token_privileges), null,null);

  


4. "Turn Off Computer" button implementation function

void Cshutdowndlg::onbnclickedbtclose () {//TODO: Add control Notification Handler code ExitWindowsEx (ewx_poweroff,0) here; MessageBox ("hahaha", "This you all Believe");}

  

"Restart" button implementation function

void Cshutdowndlg::onbnclickedbtreset () {//TODO: Add control Notification Handler code ExitWindowsEx (ewx_reboot,0) here; MessageBox ("hahaha", "This you all Believe");}

  

"Log Off Computer" button implementation function

void Cshutdowndlg::onbnclickedbtlogout () {//TODO: Add control Notification Handler code ExitWindowsEx (ewx_logoff,0) here; MessageBox ("hahaha", "This you all Believe");}

  

Implementing a computer restart

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.