osquery/core/windows/process_ops.cpp
bool isUserAdmin() {
  HANDLE hToken = nullptr;
  if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
    return false;
  }
  TOKEN_ELEVATION Elevation;
  DWORD cbSize = sizeof(TOKEN_ELEVATION);
  if (GetTokenInformation(
          hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize) ==
      0) {
    CloseHandle(hToken);
    return false;
  }
  if (hToken != nullptr) {
    CloseHandle(hToken);
  }
  return Elevation.TokenIsElevated ? true : false;
}
// Helper function to determine if thread is running with admin privilege.
Helper function to determine if thread is running with admin privilege.
Helper function to determine if thread is running with admin privilege .
bool isUserAdmin() {
  HANDLE hToken = nullptr;
  if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken)) {
    return false;
  }
  TOKEN_ELEVATION Elevation;
  DWORD cbSize = sizeof(TOKEN_ELEVATION);
  if (GetTokenInformation(
          hToken, TokenElevation, &Elevation, sizeof(Elevation), &cbSize) ==
      0) {
    CloseHandle(hToken);
    return false;
  }
  if (hToken != nullptr) {
    CloseHandle(hToken);
  }
  return Elevation.TokenIsElevated ? true : false;
}
bool isUserAdmin ( ) { HANDLE hToken = nullptr ; if ( ! OpenProcessToken ( GetCurrentProcess ( ) , TOKEN_QUERY , & hToken ) ) { return false ; } TOKEN_ELEVATION Elevation ; DWORD cbSize = sizeof ( TOKEN_ELEVATION ) ; if ( GetTokenInformation ( hToken , TokenElevation , & Elevation , sizeof ( Elevation ) , & cbSize ) == 0 ) { CloseHandle ( hToken ) ; return false ; } if ( hToken != nullptr ) { CloseHandle ( hToken ) ; } return Elevation . TokenIsElevated ? true : false ; }
Helper function to determine if thread is running with admin privilege.
Helper function to determine if thread is running with admin privilege .