Error when trying to write to .exe.config file
-
I have a windows application that is installed under ProgramFiles folder on Window7 based computer. During the launch of application some questions are asked to the user and written to the .exe.config file using ConfigurationManager.Save() method. This .exe.config file is also in ProgramFiles folder. When a user with Administrator priviledges launch application, everything works fine. But when a Standard User launch same application then application throws ConfigurationErrorsException saying that Access to path .exe.config is denied. It actually points to some .tmp file in same directiory. The name of this tmp file changes ever time user get this error but in the detail of exception always points to .exe.config file. What is the best way of addressing this problem? Remember this config file need to be accessed by all users who login and use this application. TIA
-
I have a windows application that is installed under ProgramFiles folder on Window7 based computer. During the launch of application some questions are asked to the user and written to the .exe.config file using ConfigurationManager.Save() method. This .exe.config file is also in ProgramFiles folder. When a user with Administrator priviledges launch application, everything works fine. But when a Standard User launch same application then application throws ConfigurationErrorsException saying that Access to path .exe.config is denied. It actually points to some .tmp file in same directiory. The name of this tmp file changes ever time user get this error but in the detail of exception always points to .exe.config file. What is the best way of addressing this problem? Remember this config file need to be accessed by all users who login and use this application. TIA
The Program Files folder is about the worst place you can put global settings like that. If a normal user doesn't have an admin account, you're out of luck and have to move your settings to somewhere else that is writable by normal users. Think "CommonApplicationData", here[^]. If you're users do have an admin account, then you'd add a manifest file to your project and tell it that the app requires admin priv's to run. This is not the best way to do this since you're essentially forcing users to be an admin on the machine.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
The Program Files folder is about the worst place you can put global settings like that. If a normal user doesn't have an admin account, you're out of luck and have to move your settings to somewhere else that is writable by normal users. Think "CommonApplicationData", here[^]. If you're users do have an admin account, then you'd add a manifest file to your project and tell it that the app requires admin priv's to run. This is not the best way to do this since you're essentially forcing users to be an admin on the machine.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009... -
Appreciate your quick reply. So are you suggesting to store .exe.config into CommonApplicationData folder during the installation of project? Can this folder be referred in installed package?
You can do that or you can have your code create this file on first launch if it doesn't exist. It's up to you.
imak wrote:
Can this folder be referred in installed package?
Sure. How you do that depends on which .MSI packaging software you're using. Myself, I use InnoSetup and Wise Package Studio. It don't use the Setup and Deployment stuff in Visual Studio.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008
But no longer in 2009...