How to prevent a user from changing a file manually?

In a WPF application, I use .txt files to store some information. Application can read and write data from / to .txt file. Everything is fine, but the problem is that in order to achieve this goal I have to grant write permissions to these files for the application user, and therefore he / she gets the opportunity to edit these files manually.

How can I set permissions for .txt files for applications without granting the same level of rights to the user?

Edited (added):

After receiving comments and answers, I posed the question this way (just to make my question more understandable and not limited to the user's access rights): How can I prevent the user from manually changing the file?

+4
source share
3 answers

Encrypt it or digital sign

+6
source

I assume that you are not trying to prevent the user from changing the file manually, you just want to prevent an additional step that specifically assigns rights to the file.

Most likely you are writing a file located in a protected area (the area that was protected after entering UAC). To avoid this, write the file to one of the "approved" areas, for example% APPDATA%. Here is a list of a few more (assuming C is your boot disk):

C:\Users\username\Documents C:\Users\username\AppData\Local C:\Users\username\AppData\Roaming C:\Users\Public\Documents C:\ProgramData 

This article has a whole bunch of information around from which you can blacken bits of choice.

+3
source

It may be brute force, but you can create a service that works with a different user account that can edit the file. Then your application will use this service to access the file.

This way you can prevent unwanted changes and / or log all changes to the file.

+3
source

Source: https://habr.com/ru/post/1303318/


All Articles