關閉電腦,重新啟動電腦,登出
來源:互聯網
上載者:User
//關機
if(AfxMessageBox("是否要關閉電腦?",MB_YESNO)==IDYES)
{
HANDLE htoken;
TOKEN_PRIVILEGES tkp;
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,(PTOKEN_PRIVILEGES)NULL,0);
::ExitWindowsEx(EWX_POWEROFF,NULL);
}
//重新啟動
if(AfxMessageBox("是否要重新啟動電腦?",MB_YESNO)==IDYES)
{
HANDLE htoken;
TOKEN_PRIVILEGES tkp;
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,(PTOKEN_PRIVILEGES)NULL,0);
::ExitWindowsEx(EWX_REBOOT,NULL);
}
//登出
if(AfxMessageBox("是否需要登出?",MB_YESNO)==IDYES)
::ExitWindowsEx(EWX_LOGOFF,NULL);