Reputation: 111
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.
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.
Upvotes: 3
Views: 2891
Reputation: 2116
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:
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);
Upvotes: 0
Reputation: 121
Vista and beyond will not allow user modification of files in program files dir. You should be storing them in AppData.
Upvotes: 2
Reputation: 36
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.
Upvotes: 1
Reputation: 402
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.
Upvotes: 0