禁用用户删除App.config文件 [英] Disable App.config file deletion by user

查看:178
本文介绍了禁用用户删除App.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Windows窗体应用程序,它使用App.config文件存储数据库连接和其他邮件服务器详细信息。此应用程序将安装在单个塔式系统上的企业内部网网络上,多个用户通过远程桌面连接连接到该系统并运行该应用程序。



此应用仅读取来自配置的信息并且不会向其写入任何信息。



当我首先运行应用程序时,我检查App.config文件是否存在于目录中应用程序已安装。



如果找不到配置文件,应用程序会退出,向用户显示相应的消息。



我想要在为用户运行应用程序时禁用任何用户删除此文件。



截至目前,如果用户能够删除配置文件,因为他们知道文件的位置。



目前的问题是,一些用户不知道在应用程序运行时删除此文件的人是谁,导致异常被抛出并导致应用程序崩溃。



我想在应用程序的下一次迭代中添加这些功能。



只是对任何可以回答的人的查询。

使用配置文件的exe不会在应用程序运行时获取配置文件的锁定。



请帮助

提前致谢。

解决方案

在文件级别实施适当的安全性,以便他们的帐户无法删除该文件。您的问题不是编码问题,而是系统管理问题。你不能阻止人们删除他们有权删除的文件,除非你加载文件并保持锁定。


有几种解决方案:

1)首先要修复文件删除权限问题

2)您可以在应用程序的资源中添加app.config文件的内容;如果文件在应用程序启动时不存在,则可以将其从资源复制到新文件,而不是向用户显示错误消息。


您始终可以保护任何文件删除,但仅限于它正在运行的时间。它足以打开文件并在运行时保持打开状态。默认情况下,该文件为独占访问打开。用户将无法在运行时删除此文件。



但是,您是否可以永久阻止删除该文件?不,它根本没有任何意义。我会尝试解释原因。


我甚至不想讨论用户完全控制的简单点系统,但您的软件产品没有。用户有权删除任何文件,或不是产品的一部分,并承担后果。这是您的用户的系统,而不是您的用户。 即使您能够永久禁止删除任何文件,也会从根本上违反非常基本的客户权利。



更重要的一点是< b> App.Config的目的。首先,产品中没有App.Config这样的文件。此文件只是开发工件,您可以在其中编辑默认配置的文件。进入构建输出的配置文件本身是名称与应用程序名称匹配的文件。如果条目程序集的主可执行模块的名称是MyApplication.exe,则配置文件将转到MyApplication.exe.config。



此文件的目的是更改用户的配置。并且可以由用户删除用户可以编辑的文件。顺便说一下,如果没有配置文件,最好开发具有合理回退行为的应用程序。我明白这可能并不容易,也不总是可行。




-SA

I have an windows form application which uses a App.config file for storing database connection and other mailing server details. This app is to be installed on a corporate intranet network on a single tower system to which multiple users connect via Remote Desktop Connection and run the application.

This app only reads information from the config and does not write any information to it.

When i run the application first up i check if the App.config file exists in the directory where the application has been installed.

If the config file is not found application exits showing appropriate message to the user.

I want to disable the deletion of this file by any user when the application is running for the users.

As of now if the users are able to delete the config file as they know the location of the file.

The problem currently is some users don't know who but delete this file when the application is running this results in an exception being thrown and causes the application to crash.

I want to add this features in the next iteration of the application.

Just an query i have for anybody who can answer.
Doesn't the exe using the config file acquire an lock on the config file while the app is running.

Please help
Thanks in advance.

解决方案

Implement the appropriate security at the file level so their accounts can't delete the file. Your problem isn't a coding one but a system administration one. You can't stop people deleting files they have permissions to delete, unless you load the file and keep it locked.


There are several solutions:
1) First thing would be to fix the file-delete permission problem
2) You could add the content of your app.config file in the resources of your application ; if the file is not present at application startup, you can then copy it from resources to a new file, instead of presenting an error message to the user.


You can always protect any file from deletion, but only for the time it's running. It's enough to open the file and keep it open during runtime. By default, the file is open for exclusive access. The user won't be able to delete this file during run time.

But could you permanently prevent deletion of the file? No, and it would not make any sense at all. I'll try to explain why.

I don't even want to discuss the simple point that the user has a full control at the system, but your software product doesn't. The user has every right to delete any file, a part of your product or not, and face the consequences. This is the system of your user, not yours. Even if you were able to prevent deletion of any file permanently, it would fundamentally violate very basic customer's rights.

More essential point is the purpose of the App.Config. First of all, there is no such file as App.Config in the product. This file is just the development artifact, the file where you can edit default configuration. The configuration file itself which goes to the output of the build is the file which name matches the application name. If the name of the main executable module of your entry assembly is "MyApplication.exe", the configuration file goes to "MyApplication.exe.config".

The purpose of this file is to alter the configuration by the user. And the file which can be edited by the user can be deleted by the user. And, by the way, it would be good to develop the application with reasonable fallback behavior in case of the absence of the configuration file. I do understand that it can be not easy and not always possible.


—SA


这篇关于禁用用户删除App.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆