I'm havi开发者_如何学JAVAng 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.
Vista and beyond will not allow user modification of files in program files dir. You should be storing them in AppData.
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.
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.
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:
- Right click on the project and go to Properties.
- Click on Settings.
- 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);
精彩评论