Wednesday, March 13, 2013

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!");

No comments:

Post a Comment