Created
December 8, 2016 01:50
-
-
Save camark/82fcbf03dd9b3a66e7060e33ffb96812 to your computer and use it in GitHub Desktop.
C关机
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| HANDLE hToken; | |
| TOKEN_PRIVILEGES tkp; | |
| if (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_SHUTDOWN|EWX_POWEROFF, 0); //ExitWindowsEx(EWX_POWEROFF,0)) // 关闭计算机; ExitWindowsEx(EWX_REBOOT,0) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment