简体   繁体   English

C#app.config文件和UAC

[英]C# app.config files and UAC

I started out with my application writing the config to the registry like I did years back with UAC wasn't around. 我开始使用我的应用程序将配置写入注册表,就像我多年前在UAC上做的那样。

Turned out this wasn't a good idea so I moved to the app.config file and found that this is having issues as well with UAC. 原来这不是一个好主意,所以我转移到app.config文件,发现这也与UAC有问题。

The configuration I have for the application is machine specific; 我对应用程序的配置是特定于机器的; individual users do not have their own configuration and the rest of the apps including the service all drive off the single configuration file. 个人用户没有自己的配置,其他应用程序(包括服务)都驱动单个配置文件。

If I try updating this file in the program files\\myapp folder it gets denied. 如果我尝试在程序files \\ myapp文件夹中更新此文件,则会被拒绝。

What is everyone else doing for a scenario like this where there needs to be a single configuration file? 对于需要单个配置文件的情况,其他所有人都在做什么?

I should also mention that this configuration needs to be updated from within my applications. 我还要提一下,这个配置需要从我的应用程序中更新。

I would use the Common Application Data folder, this is where most new applications store data which works with UAC. 我会使用Common Application Data文件夹,这是大多数新应用程序存储与UAC一起使用的数据的地方。

You can get this with the following code: 您可以使用以下代码获取此信息:

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)

To view all options for special folders you can check this link: 要查看特殊文件夹的所有选项,您可以查看以下链接:

http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx

The most common options would be the following: 最常见的选项如下:

Application Data - The directory that serves as a common repository for application-specific data for the current roaming user. 应用程序数据 - 用作当前漫游用户的特定于应用程序的数据的公共存储库的目录。

Common Application Data - The directory that serves as a common repository for application-specific data that is used by all users. 公共应用程序数据 - 用作所有用户使用的特定于应用程序的数据的公共存储库的目录。

Local Application Data - The directory that serves as a common repository for application-specific data that is used by the current, non-roaming user. 本地应用程序数据 - 用作当前非漫游用户使用的特定于应用程序的数据的公共存储库的目录。

You should be storing your users' settings in app.config you should be using user.config . 您应该在app.config存储用户的设置,您应该使用user.config Have a look here for more info. 在这里查看更多信息。

Any machine-wide configuration files should be stored in: 任何机器范围的配置文件都应存储在:

Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData);

Files in Program Files shouldn't be modified except when the application is installed/updated. 除非安装/更新应用程序,否则不应修改程序文件中的文件。

I had a similar need with a WPF application. 我对WPF应用程序有类似的需求。 What I do is the following: 我所做的是以下内容:

  1. Install the application with a boiler-plate configuration file. 使用样板配置文件安装应用程序。
  2. When the app runs, it checks for a config file in the user's App Datadirectory for configuration files, if they're not present it copies the default boiler-plate config files from the install directory. 当应用程序运行时,它会在用户的App Datadirectory中检查配置文件中的配置文件,如果它们不存在,则会从安装目录中复制默认的样板配置文件。
  3. I then do any first-run initialization stuff that is needed. 然后我做任何需要的首次运行初始化的东西。

I started out using the .NET ConfigurationManager, but I switched over to a plain old XML files because it was simpler and my requirements were basic. 我开始使用.NET ConfigurationManager,但我切换到一个普通的旧XML文件,因为它更简单,我的要求是基本的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM