anshdadhich commited on
Commit
5f98228
·
verified ·
1 Parent(s): aa2084e

Upload FastSeekWpf/Core/Elevation.cs

Browse files
Files changed (1) hide show
  1. FastSeekWpf/Core/Elevation.cs +45 -0
FastSeekWpf/Core/Elevation.cs ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ using System;
2
+ using System.ComponentModel;
3
+ using System.Runtime.InteropServices;
4
+ using System.Security.Principal;
5
+
6
+ namespace FastSeekWpf.Core;
7
+
8
+ public static class Elevation
9
+ {
10
+ /// <summary>
11
+ /// Returns true if the current process is running with Administrator privileges.
12
+ /// </summary>
13
+ public static bool IsElevated()
14
+ {
15
+ try
16
+ {
17
+ using var identity = WindowsIdentity.GetCurrent();
18
+ var principal = new WindowsPrincipal(identity);
19
+ return principal.IsInRole(WindowsBuiltInRole.Administrator);
20
+ }
21
+ catch
22
+ {
23
+ return false;
24
+ }
25
+ }
26
+
27
+ /// <summary>
28
+ /// Returns a human-readable elevation status string.
29
+ /// </summary>
30
+ public static string StatusText()
31
+ {
32
+ if (IsElevated())
33
+ return "Administrator (elevated)";
34
+
35
+ try
36
+ {
37
+ using var identity = WindowsIdentity.GetCurrent();
38
+ return $"{identity.Name} (NOT elevated)";
39
+ }
40
+ catch
41
+ {
42
+ return "Unknown (NOT elevated)";
43
+ }
44
+ }
45
+ }