Last active
October 17, 2016 06:13
-
-
Save chowey/bc9c9eae37e34fb5b534 to your computer and use it in GitHub Desktop.
C++ Win32 Shutdown With Privilages
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
#include <Windows.h> | |
int _tmain(int argc, _TCHAR* argv[]) | |
{ | |
HANDLE hToken; | |
OpenProcessToken(GetCurrentProcess(), | |
TOKEN_ADJUST_PRIVILEGES | | |
TOKEN_QUERY, | |
&hToken); | |
TOKEN_PRIVILEGES tk; | |
tk.PrivilegeCount = 1; | |
tk.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; | |
LookupPrivilegeValue( | |
NULL, | |
TEXT("SeShutdownPrivilege"), | |
&tk.Privileges[0].Luid); | |
AdjustTokenPrivileges( | |
hToken, | |
FALSE, | |
&tk, | |
0, | |
NULL, | |
0); | |
InitiateSystemShutdownEx( | |
NULL, | |
NULL, | |
0, | |
FALSE, | |
TRUE, | |
SHTDN_REASON_MAJOR_OTHER | | |
SHTDN_REASON_MINOR_OTHER); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Who needs error checking?