Check your application’s running location and user rights

//Get the running drive of this application
Console.WriteLine(Directory.GetDirectoryRoot(Assembly.GetExecutingAssembly().Location));
String sddlAdmins = "S-1-5-32-544";  //Sid of administrators group
IdentityReference AdminsSid = new SecurityIdentifier(sddlAdmins);
if (WindowsIdentity.GetCurrent().Groups.Contains(AdminsSid))
    Console.WriteLine("Running with admin rights!");

Comments

Popular posts from this blog

Convert XElement to DataTable

Enable mouse scroll-wheel in VB6

Performance of 'is' vs typeof (Reflection) in C#