1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| //---------------------------------------------------------------------------
void TForm1::AdjustToken()
{
HANDLE hProcess, hToken;
LUID tmpLuid;
TOKEN_PRIVILEGES tkp, tkpIgnored;
DWORD lBufferNeeded;
hProcess= GetCurrentProcess();
OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tmpLuid);
tkp.PrivilegeCount=1;
tkp.Privileges[0].Luid=tmpLuid;
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(tkpIgnored), &tkpIgnored,
&lBufferNeeded);
if(rgChoix->ItemIndex==1) ExitWindowsEx(EWX_REBOOT,0); // redémarrage
else ExitWindowsEx(EWX_POWEROFF,0); // Arrêt
}
//--------------------------------------------------------------------------- |