Skip to content

Instantly share code, notes, and snippets.

@camark
Forked from chowey/main.cpp
Created October 17, 2016 06:13
Show Gist options
  • Select an option

  • Save camark/952f3dffe380f195ce059bd435af86f8 to your computer and use it in GitHub Desktop.

Select an option

Save camark/952f3dffe380f195ce059bd435af86f8 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment