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