"API" Windows program elevation permission function

Source: Internet
Author: User

BOOL Enableshutdownprivilege () {HANDLE hprocess = NULL; HANDLE htoken = NULL; LUID UID = {0}; Token_privileges sttoken_privileges = {0}; hprocess =:: GetCurrentProcess (); Gets the current application process handle if (!::openprocesstoken (Hprocess,token_adjust_privileges,&htoken))//Opens the access token handle for the current process ( The OpenProcessToken function call failed with a return value of 0) {return FALSE;} if (!::lookupprivilegevalue (NULL,SE_SHUTDOWN_NAME,&UID))//get permission name called "SeShutdownPrivilege" Luid (the Lookupprivilegevalue function call failed with a return value of 0) {return FALSE;} sttoken_privileges.privilegecount = 1; Number of permissions to adjust Sttoken_privileges.privileges[0]. Luid = UID; Permissions of Luid Sttoken_privileges.privileges[0]. Attributes = se_privilege_enabled; The property of the permission, se_privilege_enabled to enable the permission if (!::adjusttokenprivileges (htoken,false,&sttoken_privileges,sizeof Sttoken_privileges,null,null)//Adjust the specified permission in the access token (the AdjustTokenPrivileges function call failed with a return value of 0) {return FALSE;} if (:: GetLastError ( ) = ERROR_SUCCESS)//See if the permissions are adjusted successfully {return FALSE;}:: CloseHandle (Htoken); return TRUE;}

API Windows Program elevation permission function

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.