Skip to content

Instantly share code, notes, and snippets.

@chowey
Last active October 17, 2016 06:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save chowey/bc9c9eae37e34fb5b534 to your computer and use it in GitHub Desktop.
Save chowey/bc9c9eae37e34fb5b534 to your computer and use it in GitHub Desktop.
C++ Win32 Shutdown With Privilages
#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;
}
@chowey
Copy link
Author

chowey commented Apr 30, 2014

Who needs error checking?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment