阅读:942回复:1
如何在系统注销的时候强制机器重起
可以在程序中知道系统需要注销,可这个时候我需要reboot,于是我重载了WindowProc,
LRESULT CMainFrame::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) { if (message == WM_QUERYENDSESSION) { if (lParam & ENDSESSION_LOGOFF) { //log off OutputDebugString("lOG OFFn"); if(HIWORD(m_dwWindowsType)==OSVER_WINNT) { HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return FALSE; // Get the LUID for the shutdown privilege. if(!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid)) return FALSE; tkp.PrivilegeCount=1; // one privilege to set tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED; // Get the shutdown privilege for this process. if(!AdjustTokenPrivileges(hToken, FALSE, &tkp, 0,(PTOKEN_PRIVILEGES)NULL,0)) return FALSE; } OutputDebugString("Before restartn"); if(!ExitWindowsEx(EWX_REBOOT,0)) { DWORD dwError=GetLastError(); char msg[128]; sprintf(msg,"Restart windows error,code is %ldn",dwError); OutputDebugString(msg); } OutputDebugString("endn"); //return TRUE; } else { //restart } } return CFrameWnd::WindowProc(message, wParam, lParam); } 可是发现机器还是注销,不是重起,有谁知道怎么办么? [编辑 - 8/10/04 by nustzhua] |
|
|