VC++簡略完成關機、重啟盤算機實例代碼。本站提示廣大學習愛好者:(VC++簡略完成關機、重啟盤算機實例代碼)文章只能為提供參考,不一定能成為您想要的結果。以下是VC++簡略完成關機、重啟盤算機實例代碼正文
本文以一個實例情勢引見了VC++簡略完成關機、重啟盤算機的辦法,代碼比擬適用,有必定的參考價值。完全實例代碼以下:
void CWebBrowserView::OnMenuShutdown() { // TODO: 在此添加敕令處置法式代碼 if (AfxMessageBox("肯定要關機嗎?",MB_YESNO) == IDYES) { HANDLE hToken; TOKEN_PRIVILEGES tkp; // Get a token for this process. if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) { AfxMessageBox("OpenProcessToken Error!"); return; } // Get the LUID for the shutdown privilege. LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid); tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; // Get the shutdown privilege for this process. AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, NULL); if (GetLastError() != ERROR_SUCCESS) { AfxMessageBox("關機掉敗"); return; } // Shut down the system and force all applications to close. ExitWindowsEx(EWX_SHUTDOWN | EWX_FORCE, 0); //重啟只須要把EWX_SHUTDOWN改成EWX_REBOOT } }