Skip to content

Instantly share code, notes, and snippets.

@camark
Created December 8, 2016 01:50
Show Gist options
  • Select an option

  • Save camark/82fcbf03dd9b3a66e7060e33ffb96812 to your computer and use it in GitHub Desktop.

Select an option

Save camark/82fcbf03dd9b3a66e7060e33ffb96812 to your computer and use it in GitHub Desktop.
C关机
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