using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Security.Principal;
namespace FastSeekWpf.Core;
public static class Elevation
{
///
/// Returns true if the current process is running with Administrator privileges.
///
public static bool IsElevated()
{
try
{
using var identity = WindowsIdentity.GetCurrent();
var principal = new WindowsPrincipal(identity);
return principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch
{
return false;
}
}
///
/// Returns a human-readable elevation status string.
///
public static string StatusText()
{
if (IsElevated())
return "Administrator (elevated)";
try
{
using var identity = WindowsIdentity.GetCurrent();
return $"{identity.Name} (NOT elevated)";
}
catch
{
return "Unknown (NOT elevated)";
}
}
}