龙
龙门刀客
Unregistered / Unconfirmed
GUEST, unregistred user!
试试这个:<br><br>void CshutdownDlg::Shutdown()<br>{<br> OSVERSIONINFO osv;<br> osv.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);<br> ::GetVersionEx(&osv); //获得操作系统信息<br> //如果操作系统是 WINNT,那么调整当前进程得优先权<br> if(osv.dwPlatformId==VER_PLATFORM_WIN32_NT)<br> {<br> HANDLE hProcess,hToken;<br> TOKEN_PRIVILEGES Privileges;<br> LUID luid;<br> hProcess = ::GetCurrentProcess();<br> ::OpenProcessToken(hProcess,TOKEN_ADJUST_PRIVILEGES,&hToken);<br> Privileges.PrivilegeCount = 1;<br> ::LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&luid);<br> Privileges.Privileges[0].Luid = luid;<br> Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;<br> ::AdjustTokenPrivileges(hToken,FALSE,&Privileges,NULL,NULL,NULL);<br> ::ExitWindowsEx(EWX_SHUTDOWN|EWX_FORCE|EWX_POWEROFF,0);<br> }<br> else<br> ::ExitWindowsEx(EWX_SHUTDOWN,0);<br>}