Last active
December 23, 2018 08:38
-
-
Save yjfvictor/bbe0640c778d71829425 to your computer and use it in GitHub Desktop.
Shut down and power off on Windows NT/2000/XP/7/8
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
/** | |
* NT_shutdown.c - Shut down and power off on Windows NT/2000/XP/7/8 | |
* 用于给Windows NT/2000/XP/7/8关机的程序 | |
* | |
* Written in 2014 by yjf_victor | |
* | |
* To the extent possible under law, the author has dedicated all copyright | |
* and related and neighboring rights to this software to the public domain | |
* worldwide. This software is distributed without any warranty. | |
* | |
* You should have received a copy of the CC0 Public Domain Dedication along with | |
* this software. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>. | |
* | |
*/ | |
#include <windows.h> | |
#ifndef EWX_FORCEIFHUNG | |
#define EWX_FORCEIFHUNG 0x00000010 | |
#endif | |
int main(void) | |
{ | |
HANDLE token; | |
TOKEN_PRIVILEGES tp; | |
if(OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) | |
{ | |
LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &(tp.Privileges[0].Luid)); | |
tp.PrivilegeCount = 1; | |
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
AdjustTokenPrivileges(token, FALSE, &tp, 0, NULL, 0); | |
} | |
ExitWindowsEx(EWX_FORCE | EWX_SHUTDOWN | EWX_POWEROFF | EWX_FORCEIFHUNG, 0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
win7实测ok