Reputation: 5615
I have a folder that I want to protect its contents, I'm denying full control to it by this code:
void changeFolderPermission(string folder, FileSystemRights rights, AccessControlType type)
{
DirectoryInfo myDirInfo = new DirectoryInfo(folder);
DirectorySecurity myDirSecurity = myDirInfo.GetAccessControl();
string user = System.Environment.UserName;
myDirSecurity.ResetAccessRule(new FileSystemAccessRule(user, rights, type));
myDirInfo.SetAccessControl(myDirSecurity);
}
I'm using it like this:
changeFolderPermission(FolderName, FileSystemRights.FullControl, AccessControlType.Deny);
It's working fine, I mean, when i try to open the folder, it won't let me. Problem is, I could easily remove that permission by right clicking on the folder, going to security, look for that special permission and just deleting it ..
is there a way to prevent someone from doing this ? I want the folder to be fully secured.
Now I know that there's something like this:
hangeFolderPermission(FolderName, FileSystemRights.ChangePermissions, AccessControlType.Deny);
but I'm still being able to change the permissions.
any help would be appreciated .. thanx alot in advance .. :)
Upvotes: 2
Views: 1131
Reputation: 33738
You never said anything in your original post about sending the folder to other people. Presumably this sending mechanism involves email, ftp, etc to ANOTHER COMPUTER. Assumption #2 is that your C# program is what will be reading the contents of said folder.
In this case its simple, create a password-protected zip file of your directory and send that. Then embed the password within your C# code and open the zip file and read its contents.
There are several really good zip manipulation libraries out there such as dotnetzip and #ziplib
Upvotes: 3
Reputation: 33738
You can not prevent a user with admin rights from accessing a folder or file.
If the user does not have admin rights, then set the permissions (via an admin account) to deny the user access. Properly configured permissions will prevent the non-admin user from accessing the folder/file.
Upvotes: 4