static void Main(string[] args) { var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); Console.WriteLine($"Administrator: {(principal.IsInRole(WindowsBuiltInRole.Administrator) ? "YES" : "NO")}"); Console.WriteLine($"Elevated: {(ProcessSecurity.GetProcessElevated() ? "YES" : "NO")}"); Console.WriteLine($"Integrity: {ProcessSecurity.GetCurrentProcessIntegrity()}"); }
public MainForm() { InitializeComponent(); var identity = WindowsIdentity.GetCurrent(); var principal = new WindowsPrincipal(identity); if (principal.IsInRole(WindowsBuiltInRole.Administrator)) { lblAdmin.Text = $"Administrator: YES"; lblAdmin.ForeColor = Color.Maroon; } else { lblAdmin.Text = $"Administrator: NO"; lblAdmin.ForeColor = Color.Green; } if (ProcessSecurity.GetProcessElevated()) { lblElevated.Text = $"Elevated: YES"; lblElevated.ForeColor = Color.Maroon; } else { lblElevated.Text = $"Elevated: NO"; lblElevated.ForeColor = Color.Green; } switch (ProcessSecurity.GetCurrentProcessIntegrity()) { case ProcessSecurity.Integrity.System: lblIntegrity.Text = "Integrity: SYSTEM"; lblIntegrity.ForeColor = Color.Crimson; break; case ProcessSecurity.Integrity.High: lblIntegrity.Text = "Integrity: HIGH"; lblIntegrity.ForeColor = Color.Maroon; break; case ProcessSecurity.Integrity.Medium: lblIntegrity.Text = "Integrity: MEDIUM"; lblIntegrity.ForeColor = Color.Green; break; case ProcessSecurity.Integrity.Low: lblIntegrity.Text = "Integrity: LOW"; lblIntegrity.ForeColor = Color.LimeGreen; break; default: lblIntegrity.Text = "Integrity: ?"; lblIntegrity.ForeColor = Color.Black; break; } }