C # save directory permissions

I am trying to find a way to store permissions in a directory. I am currently using SetACL for help. If I could change the ownership of directories / registry without it, that would be preferable, but that's a different story. Example:

Check owner and permissions for this owner. Go to permissions and the owner on the button click> change it back to the original when another button is pressed.

To keep the question of why my team provides technical support. We retire to the computer, execute our t / s and leave. We should be able to change permissions and then return them back, as it were.

Any help is appreciated.

+3
source share
1

System.Management System.Management.Instrumentation, Directory.GetAccessControl, . AddAccessRule SetAccessControl . , . , , :

http://www.redmondpie.com/applying-permissions-on-any-windows-folder-using-c/

, , :

DirectoryInfo myDirectoryInfo = new DirectoryInfo(yourFolderHere);

// Get a DirectorySecurity object that represents the 
// current security settings.
DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();

// Builds a new user string for who we want to give permissions to
string User = System.Environment.UserDomainName + "\\" + yourUserName; 

// Creates the permissions to apply 
myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(User, 
                                  FileSystemRights.FullControl, AccessControlType.Allow));

// Set the new access settings. 
myDirectoryInfo.SetAccessControl(myDirectorySecurity);

// Showing a Success Message
MessageBox.Show("Permissions Altered Successfully");
}

, SO , :

# - DirectorySecurity.SetOwner()? ...

, , - ( , , ), . , - , . :

http://blog.salamandersoft.co.uk/index.php/2009/10/setting-the-owner-of-files-and-directories-in-c/

+4

All Articles