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