restrict access to folder outside of program c#

2019-07-19 07:44发布

问题:

I am developing a C# application which saves data to a folder. I want the folder to be restricted to all users in file explorer and only accessible programmatically through the application. So the application has full access to the folder, but it cannot be accessed directly through windows. How can I accomplish this?

回答1:

In Windows permissions are per-user, and there are no "per-application" permissions.

So to be able to prevent current user who runs the application from accessing the folder you'll need to run code that read/wirites the data in the folder to impersonate another account. Than you'll be able to set permission to be accessible to just that user.

Note that if user have admin privileges such user still can get access to the folder by overwriting your security settings.