关机、注销、重启
DWORD dwVer = GetVersion(); // Version of OS
if (dwVer < 0x80000000 )
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if ( !OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken) )
return;
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid);
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, NULL, 0);
ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE, 0); // shutdown
// ExitWindowsEx(EWX_SHUTREBOOT | EWX_FORCE, 0); // reboot
// ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0); // poweroff
// ExitWindowsEx(EWX_LOGOFF | EWX_FORCE, 0); // logoff
}
else
{
ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE, 0); // shutdown
// ExitWindowsEx(EWX_SHUTREBOOT | EWX_FORCE, 0); // reboot
// ExitWindowsEx(EWX_POWEROFF | EWX_FORCE, 0); // poweroff
// ExitWindowsEx(EWX_LOGOFF | EWX_FORCE, 0); // logoff
}
阅读(886) | 评论(0) | 转发(0) |