如何允许用户使用记事本或其他编辑器编辑Program Files下的App.config?

发布于 2024-11-14 00:48:25 字数 389 浏览 5 评论 0原文

我遇到了一个以前从未遇到过的问题,即使 Windows 服务未运行,安装在“Program Files (x86)”目录下的 Windows 服务的 App.configs 也会被锁定以进行编辑。我收到一条消息,表明该文件正在使用中,即使它不应该使用。

  • 这是将 Windows 服务的 .config 文件放在 Program Files 目录下的具体情况吗?
  • 如何允许知道 .config 文件位置的用户在记事本或其他编辑器中编辑它,而不会收到文件“正在使用”消息。

我已尝试在三台不同的计算机上安装 Windows 服务,并确保该服务并未实际启动/运行。我希望获得一些关于为什么这不起作用的知识,因为在过去我已经对恰好位于目录中的 .exe 进行了可编辑的 app.configs 。

I'm having an issue that I have not encountered before where App.configs for Windows Services that are installed under the "Program Files (x86)" directory are locked for editing even when the Windows Services are not running. I get a message that the file is in use, even when it should not be.

  • Is this something specific about putting a .config file for a Windows Service under the Program Files directory?
  • How can I allow a user that knows the location of the .config file to edit it in Notepad or another editor without receiving the file is "in use" message.

I have tried the install of the Windows Service on three different machines and ensured the service is not actually started/running. I'm hoping to gain some knowledge on why this is not working as in the past I have had app.configs editable for .exes that happen to live in a directory.

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

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

发布评论

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

评论(4

雅心素梦 2024-11-21 00:48:25

Vista 及更高版本不允许用户修改程序文件目录中的文件。您应该将它们存储在 AppData 中。

Vista and beyond will not allow user modification of files in program files dir. You should be storing them in AppData.

清引 2024-11-21 00:48:25

发生这种情况可能是因为该文件受到写保护,您应该右键单击它(或其包含的文件夹),选择属性,然后在安全性下添加您的用户对此文件的完全控制权。只需确保不要通过向所有用户添加完全控制来在您的应用程序中创建安全漏洞。
您也可以尝试右键单击->打开该文件。以管理员身份运行,可能会成功。

It might happen because the file is write protected, you should right click on it (or it's containing folder), choose properties, and under security, add your user full control over this file. just make sure not to create a security breech in your application by adding full control to all users.
You can also try opening the file with right-click -> Run as Administrator, it might do the trick.

等风也等你 2024-11-21 00:48:25

如果您使用 Vista、Windows Server 2008 或 Windows 7,那么我想说它可能是 UAC 阻止您进行保存(我认为这会由于您使用的 Program Files 路径而启动)。尝试以管理员身份运行记事本(在开始栏中找到记事本,右键单击并选择以管理员身份运行),然后打开文件进行编辑并尝试保存。

If your using Vista, Windows Server 2008 or Windows 7, then I'd say its probably UAC preventing you from doing the save (which I think will be kicking in due to the Program Files path your using). Have a go at running notepad as administrator (find notepad in the start bar right click and select run as administrator), then open the file do your editing and try saving.

2024-11-21 00:48:25

我之前在尝试将为 Windows XP 编写的程序安装到 Windows 7 上时遇到过这个问题。

对于 Windows XP,我总是手动在 App.config 文件中创建设置,结果如下:

<appSettings>
    <add key="port" value="48889" />
<appSettings>

对于 Windows 7,我有进行以下更改:

  1. 右键单击该项目并转到“属性”。
  2. 单击“设置”。
  3. 输入所需的应用程序设置(确保将范围设置为用户 - 对于本例)

这会将 app.config 更改为如下:

<userSettings>
    <ProjectName.Properties.Settings>
        <setting name="port" serializeAs="String">
           <value>50000</value>
        </setting>
    </ProjectName.Properties.Settings>
</userSettings>

这会将配置文件保存在用户文档和设置中。具体位置取决于您运行的 Windows 版本。但以下 C# 代码将告诉您位置:

System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData);

I have run into this problem before when trying to install a program that was written for Windows XP onto Windows 7.

For Windows XP I always created the settings in the App.config file manually and they ended up as follows:

<appSettings>
    <add key="port" value="48889" />
<appSettings>

For Windows 7 I had to make the following changes:

  1. Right click on the project and go to Properties.
  2. Click on Settings.
  3. Enter the applications settings you want (make sure to set scope to user - for this example)

This changes the app.config to be as follows:

<userSettings>
    <ProjectName.Properties.Settings>
        <setting name="port" serializeAs="String">
           <value>50000</value>
        </setting>
    </ProjectName.Properties.Settings>
</userSettings>

This will save the config file within the users documents and settings. Exactly where depends on which version of windows you are running. But the following C# code will show you where:

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