Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //mxd
- public static bool CheckWritePremissions(string path)
- {
- try
- {
- DirectoryInfo di = new DirectoryInfo(path);
- DirectorySecurity ds = di.GetAccessControl();
- AuthorizationRuleCollection rules = ds.GetAccessRules(true, true, typeof(NTAccount));
- WindowsIdentity currentuser = WindowsIdentity.GetCurrent();
- if(currentuser != null)
- {
- WindowsPrincipal principal = new WindowsPrincipal(currentuser);
- foreach(AuthorizationRule rule in rules)
- {
- FileSystemAccessRule fsar = rule as FileSystemAccessRule;
- if(fsar != null && (fsar.FileSystemRights & FileSystemRights.WriteData) > 0)
- {
- NTAccount account = rule.IdentityReference as NTAccount;
- if(account != null && principal.IsInRole(account.Value)) return true;
- }
- }
- }
- }
- catch(UnauthorizedAccessException) { }
- return false;
- }
Add Comment
Please, Sign In to add comment