Reputation: 300
my problem is, I want to create a new folder and make it impossible (or reasonably hard) for the user to change its name or to delete it. The thing is, the user must be able to access the files contained within that folder and change them in any way he pleases. Using the examples I've been finding in the net all I get is making it impossible to change the files INSIDE the folder, and not the folder itself.
Thanks in advance ;)
Upvotes: 2
Views: 511
Reputation: 265
If you are going to have a C# program open all the time to perform your tasks, based on @Teoman Soygul's answer you could add this line to your code, which will open a stream on the target directory to be 'protected' and thus, not allow users to modify it:
File.Open(@"yourDirHere.zip", FileMode.Open, FileAccess.Read);
This method only works if the directory is compressed or on files, not on standard directories. This was my use case and thought it was worth mentioning here, in case it could also be useful to anyone else. You may be interested in playing around te different accessors provided at File.Open Method
Upvotes: 0
Reputation: 25742
As long as that folder is created by the user's account (assuming that you're creating the folder programmatically by your application), the user will be able to edit the folder. The best way to protect that folder from tampering would be to write a very small windows service that keeps that folder always open, thus preventing deletion/renaming.
Upvotes: 2
Reputation: 70523
This might be helpful.
http://technet.microsoft.com/en-us/library/cc732880.aspx
It seems you want to allow the "Create Files/Write Data" permission but not allow "control" of the parent folder.
You should be able to set up an ACL to do this. Give them "List folder contents" rights and then selectively give them additional extended rights without giving them modify attributes rights.
The service answer is a bad idea. I might work, but is not the best way to do it. The key with windows directory and folder security is the "owner" of a folder. As an administrator you can always take ownership of a folder or file. BUT if the file has a different owner and that owner has granted you rights you won't have any other rights until you go in and take ownership.
What you want to do is create a special account on the machine (often called a service account) which is the identity the program runs under. This account has admin rights and is the owner of any files it creates. Then it can allow whatever access it wants to grant to users of files and folders it creates.
The admin will always be able to take ownership if they want to, but most users don't even know how to do this.
Upvotes: 2