快速關機Shutdown,含源碼。ui
公司公用的筆記本電腦實在太爛,不知從何時開始關機永遠都關不了,一直停留在「關閉系統中……」。忍無可忍之下,本身寫了一個快速關機程序。spa
下載:code
Shutdown_for_Win7-32bit.rarget
源碼:it
BOOL NtExitWindows(UINT uFlags, DWORD dwReason) { HANDLE hToken; TOKEN_PRIVILEGES tkp; if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken)) return FALSE; if (!LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &tkp.Privileges[0].Luid)) { CloseHandle(hToken); return FALSE; } tkp.PrivilegeCount = 1; // one privilege to set tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if (!AdjustTokenPrivileges(hToken, FALSE, &tkp, sizeof(TOKEN_PRIVILEGES), (PTOKEN_PRIVILEGES)NULL, (PDWORD) NULL)) { CloseHandle(hToken); return FALSE; } CloseHandle(hToken); return ExitWindowsEx(uFlags, dwReason); }
下載:class