void ShutDownWindows(unsigned int iOpt) //EWX_POWEROFF, EWX_REBOOT, EWX_LOGOFF, EWX_FORCE, EWX_SHUTDOWN
{
OSVERSIONINFO ovi;
ovi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if(GetVersionEx(&ovi))
{
if(ovi.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY, &hToken))
{
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(iOpt,0); //执行选择的命令
}
调用上面函数 ShutDownWindows(EWX_POWEROFF|EWX_SHUTDOWN);
--------------------next---------------------
阅读(1106) | 评论(0) | 转发(0) |