19 Ocak 2017 Perşembe

AdjustTokenPrivileges

Şöyle yaparız.
bool EnableShutdownPrivilege() {

  HANDLE hProcess = NULL;
  HANDLE hToken = NULL;
  LUID uID = { 0 };
  TOKEN_PRIVILEGES stToken_Privileges = { 0 };

  hProcess = ::GetCurrentProcess();

  if (!::OpenProcessToken(hProcess, TOKEN_ADJUST_PRIVILEGES, &hToken))
    return false;

  if (!::LookupPrivilegeValue(NULL, SE_SHUTDOWN_NAME, &uID))
    return false;

  stToken_Privileges.PrivilegeCount = 1;
  stToken_Privileges.Privileges[0].Luid = uID;
  stToken_Privileges.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;

  if (!::AdjustTokenPrivileges(hToken, false,
    &stToken_Privileges, sizeof(stToken_Privileges), NULL, NULL))
    return false;

  if (::GetLastError() != ERROR_SUCCESS)
    return false;

  ::CloseHandle(hToken);
  return true;
}


Hiç yorum yok:

Yorum Gönder