如何更改 .NET 用户设置位置

发布于 2024-08-26 13:04:53 字数 211 浏览 9 评论 0原文

默认情况下,设置存储在:C:\Documents and Settings\\Local Settings\Application Data\

如何将此路径更改为应用程序目录。我也不想为不同的用户提供不同的文件。如何使设置全局化?

我尝试将设置的范围更改为“应用程序”,但无法在运行时更改它们。

By default settings are stored at: C:\Documents and Settings\\Local Settings\Application Data\<Project Name>

How can I change this path to application directory. I also don't want to have different files for different users. How make the settings global?

I tried to change the scope of the settings to "application" but then I cannot change them at runtime.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毁梦 2024-09-02 13:04:53

您不能使用默认的内置行为!

问:为什么路径如此模糊?有什么办法可以改变/定制
是吗?

答:路径构建算法必须满足一定的严格要求
安全方面的要求,
隔离性和鲁棒性。当我们
试图让路径变得容易
通过使用尽可能发现
友好的,提供的应用程序
字符串,不可能保留
这条路完全简单,没有
遇到碰撞等问题
与其他应用程序、欺骗等。

LocalFileSettingsProvider 不
提供一种更改文件的方法
存储哪些设置。注意
提供商本身无法确定
第一个配置文件位置
place - 这是配置
系统。如果您需要存储
设置在不同的位置
出于某种原因,推荐的方法是
编写您自己的SettingsProvider。这
实施起来相当简单,你
可以在.NET 2.0 SDK中找到示例
展示了如何做到这一点。记住
但是你可能会遇到同样的情况
上面提到的隔离问题。

我同意 Robert Harvey 的回答,请自行操作,或编写自定义设置提供者。

Using the default built-in behavior you can't!

Q: Why is the path so obscure? Is there any way to change/customize
it?

A: The path construction algorithm has to meet certain rigorous
requirements in terms of security,
isolation and robustness. While we
tried to make the path as easily
discoverable as possible by making use
of friendly, application supplied
strings, it is not possible to keep
the path totally simple without
running into issues like collisions
with other apps, spoofing etc.

The LocalFileSettingsProvider does not
provide a way to change the files in
which settings are stored. Note that
the provider itself doesn't determine
the config file locations in the first
place - it is the configuration
system. If you need to store the
settings in a different location for
some reason, the recommended way is to
write your own SettingsProvider. This
is fairly simple to implement and you
can find samples in the .NET 2.0 SDK
that show how to do this. Keep in mind
however that you may run into the same
isolation issues mentioned above .

I agree with Robert Harvey's answer do it yourself, or write a custom settings provider.

清旖 2024-09-02 13:04:53

您始终可以读取和编写自己的 XML 配置文件

You can always read and write your own XML configuration files.

乱世争霸 2024-09-02 13:04:53

以编程方式更改所有用户的设置存在困难(因为它们来自 exe.config 文件,该文件通常位于程序文件中,因此在现代操作系统中无法进行写访问)。您可以尝试在应用程序范围内进行设置,然后使用 ConfigurationManager 来处理配置文件,类似于

There are difficulties with programmatically changing settings for all users (since they come from the exe.config file, which is usually in Program Files and thus protected from write access in modern OSes). You can try making the settings application-wide but then use the ConfigurationManager to mess with the config file, similarly to the solution to this question.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文