I used this Code to grant my application full read/write access about a path:
private void GetAccess(string fullPath)
{
DirectoryInfo dInfo = new DirectoryInfo(fullPath);
DirectorySecurity dSecurity = dInfo.GetAccessControl();
dSecurity.AddAccessRule(new FileSystemAccessRule(new
SecurityIdentifier(WellKnownSidType.WorldSid, null),
FileSystemRights.FullControl, InheritanceFlags.ObjectInherit |
InheritanceFlags.ContainerInherit,
PropagationFlags.NoPropagateInherit, AccessControlType.Allow));
dInfo.SetAccessControl(dSecurity);
}
But when it comes to dInfo.SetAccessControl(dSecurity)
it throws an UnauthorizedAccessException
although i have full administrative rights at the computer i'm using.
Is there a way to grant this access through another method or give my application any access in advance to process this command?