标签:
关机调用:
文章来源:http://dqifa.blog.163.com/blog/#m=0&t=1&c=fks_095066086083081065092081074071093084084075087080083
MyExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE | EWX_POWEROFF);
重启调用:
MyExitWindowsEx(EWX_REBOOT | EWX_FORCE);
具体实现:
BOOL IsWIN32_NT()
{
OSVERSIONINFO osv;
osv.dwOSVersionInfoSize = sizeof OSVERSIONINFO;
GetVersionEx(&osv);
return osv.dwPlatformId == VER_PLATFORM_WIN32_NT;
}
BOOL MyExitWindowsEx(UINT uFlags)
{
if(IsWIN32_NT())
{
HANDLE hProcess, hToken;
TOKEN_PRIVILEGES Privileges;
hProcess = GetCurrentProcess();
OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken);
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &Privileges.Privileges[0].Luid);
Privileges.PrivilegeCount = 1;
Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken, FALSE, &Privileges, 0, (PTOKEN_PRIVILEGES)NULL, NULL);
}
return ExitWindowsEx(uFlags, 0);
}
标签:
原文地址:http://www.cnblogs.com/yuqilihualuo/p/4611006.html