1. Shutdown code
Token_privileges TP;
Handle htoken;
Luid;
Lptstr machinename = NULL;
If (! Openprocesstoken (getcurrentprocess (), token_adjust_privileges, & htoken ))
{
// Perr ("openprocesstoken", getlasterror ());
Return;
}
If (! Lookupprivilegevalue (machinename, se_shutdown_name, & luid ))
{
// Perr ("lookupprivilegevalue", getlasterror ());
Return;
}
TP. privilegecount = 1;
TP. Privileges [0]. luid = luid;
TP. Privileges [0]. Attributes = se_privilege_enabled;
Adjusttokenprivileges (htoken, false, & TP, sizeof (token_privileges), null, null); // here, the permission is obtained ///
Exitwindowsex (ewx_poweroff, ewx_force );
2. Restart the code
Token_privileges TP;
Handle htoken;
Luid;
Lptstr machinename = NULL;
If (! Openprocesstoken (getcurrentprocess (), token_adjust_privileges, & htoken ))
{
// Perr ("openprocesstoken", getlasterror ());
Return;
}
If (! Lookupprivilegevalue (machinename, se_shutdown_name, & luid ))
{
// Perr ("lookupprivilegevalue", getlasterror ());
Return;
}
TP. privilegecount = 1;
TP. Privileges [0]. luid = luid;
TP. Privileges [0]. Attributes = se_privilege_enabled;
Adjusttokenprivileges (htoken, false, & TP, sizeof (token_privileges), null, null); // here, the permission is obtained ///
Exitwindowsex (ewx_reboot, ewx_force );