Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# administrator privilege - checking

I know that there are some similar questions. But I want to check only ONE thing.

I only want to know if program is running as administrator. I want to check that because I want to edit some secured files. User don'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.

like image 946
Hooch Avatar asked May 10 '11 16:05

Hooch


1 Answers

This will return a bool valid

using System.Security.Principal;  bool isElevated; using (WindowsIdentity identity = WindowsIdentity.GetCurrent()) {     WindowsPrincipal principal = new WindowsPrincipal(identity);     isElevated = principal.IsInRole(WindowsBuiltInRole.Administrator); } 
like image 103
atrljoe Avatar answered Oct 21 '22 07:10

atrljoe