<br /> I have a text file. I need to the following:<br /> 1. Prevent remove a file.<br /> 2. Prevent changes to the file.<br /> Even if the program is not running. Is this possible? Maybe through the use of the service?<br /> 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).<br /> Thanks.Answer1:
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.
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.Answer2:
You can use Windows RBS to ensure that the file can only be modified or deleted by Administrators and a specific system user which your program creates and can be run in that context.
NEVER block Administrators' access to files; you will catch seven levels of hell from your application's users, who can't remove this one file (and thus can't remove the installation folder) when uninstalling your app.