HANDLE hToken;
LUID ShutDownValue;
TOKEN_PRIVILEGES tkp;
if (!OpenProcessToken(GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
&hToken))
{
//AfxMessageBox("OpenProcessToken failed");
return FALSE;
}
// // Enable the SE_SHUTDOWN_NAME privilege
if (!LookupPrivilegeValue((LPSTR) NULL,
SE_SHUTDOWN_NAME,
&ShutDownValue))
{
//AfxMessageBox("LookupPrivilegeValue failed");
return FALSE;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = ShutDownValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,
FALSE,
&tkp,
sizeof(TOKEN_PRIVILEGES),
(PTOKEN_PRIVILEGES) NULL,
(PDWORD) NULL);
ExitWindowsEx(EWX_REBOOT|EWX_FORCE,0);