'Check for administrator privileges in C#

I want to know if a program is running as administrator.

The user doesn't have to be administrator. I only want to know if my application has rights to edit some secured files that are editable when running as Administrator.



Solution 1:[1]

Here's @atrljoe's answer turned into a one liner using the latest C#:

using System.Security.Principal;

static bool IsElevated => new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Bryan Legend