This is not minimalistic, but you can use this property that I created from sources on the network. Some of these calls are pInvoke. So google 'pinvoke method' to find them.
public static bool IsRunAsAdministrator { get { WindowsIdentity windowsIdentity = WindowsIdentity.GetCurrent(); if (windowsIdentity.IsSystem) return true; WindowsPrincipal windowsPrincipal = new WindowsPrincipal(windowsIdentity); if (windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator)) return true; //Vista or higher check if (Environment.OSVersion.Version.Major >= 6) { IntPtr hToken = IntPtr.Zero; try { if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, out hToken)) Win32.ThrowLastError(); TOKEN_ELEVATION_TYPE elevationType; IntPtr pElevationType = Marshal.AllocHGlobal(sizeof(TOKEN_ELEVATION_TYPE)); uint dwSize; if (!GetTokenInformation( hToken, TOKEN_INFORMATION_CLASS.TokenElevationType, pElevationType, sizeof(TOKEN_ELEVATION_TYPE), out dwSize )) Win32.ThrowLastError(); elevationType = (TOKEN_ELEVATION_TYPE)Marshal.ReadInt32(pElevationType); Marshal.FreeHGlobal(pElevationType); return elevationType == TOKEN_ELEVATION_TYPE.TokenElevationTypeFull; } finally { CloseHandle(hToken); } } else return true; } }
source share