开发者

How to prevent a user from changing a file manually?

In a WPF application I use .txt files for holding some information. An application can read and write data from/to .txt file. Everything is OK, but the problem is that, to achieve this purpose, I have to grant writing access rights to these files for a user of an application and so, he/she gets the possibility to edit these files manually.

How could I set editing .txt files access rights for an application without granting the same level of rights to a user?

E开发者_JAVA技巧dited (added):

After getting some comments and answers, I put the question this way (just to make my question more clear and not restricted to user access rights scope): How I could prevent the user from changing the file manually?


Encrypt it, or digital sign it


I'm going to presume that you are not trying to prevent the user from changing the file manually, you just want to prevent the extra step of specifically assigning rights to the file.

You are most likely writing to a file that is in a protected area (an area that became protected after UAC was introduced). To avoid this, write your file to one of the "approved" areas, such as %APPDATA%. Here is a list of a few more (assuming C is your boot drive):

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 info around that which you can cherry pick bits from.


This might be an overkill, but you could create a service that runs on a different user account, which can edit the file. Then your application would use that service to access the file.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜