问题描述
我有一个文本文件.我需要执行以下操作:
1.防止删除文件.
2.防止更改文件.
即使程序未运行.这可能吗?也许通过使用服务?
应用程序的用户可以将新数据添加到文件中.
I have a text file. I need to the following:
1. Prevent remove a file.
2. Prevent changes to the file.
Even if the program is not running. Is this possible? Maybe through the use of the service?
Users of application can add new data to a file.
常规:我需要防止文件被删除和任何更改(在应用程序外部).
谢谢.
General: I need to prevent my file from delete and any changes (outside of my app).
Thanks.
推荐答案
这将由您使用文件权限来完成.在文件安全设置的内部,您可以设置谁可以删除文件,谁可以修改文件等.您可以让应用程序提升其权限,以能够修改文件.
This would be something you do with file permissions. Inside of the files security settings, you can set who can delete the file, who can modify the file, etc. You could have the application elevate its rights to be able to modify the file.
如果应用程序未运行,则无法保护文件本身.将应用程序作为服务运行将使其保持运行状态,这将使其能够对文件执行一些保护性操作,但是随后您将需要第二个应用程序与用户进行交互,并且您还将从事操作系统的工作. .在C#应用程序内部提升权限比尝试通过代码来完成您的工作要容易得多.
If the application is not running, it cannot protect the file itself. Running the application as a service would allow it to stay running, which would allow it to perform some protective actions on the file but you would need a second application to interact with the user then and you would also be doing the job of the operating system. Elevating rights inside of the C# application is much easier than attempting to do what you are doing through code.
这篇关于防止文件被删除和更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!