Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Windows Forms
  4. Error when trying to write to .exe.config file

Error when trying to write to .exe.config file

Scheduled Pinned Locked Moved Windows Forms
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    imak
    wrote on last edited by
    #1

    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

    D 1 Reply Last reply
    0
    • I imak

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      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...

      I 1 Reply Last reply
      0
      • D Dave Kreskowiak

        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...

        I Offline
        I Offline
        imak
        wrote on last edited by
        #3

        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?

        D 1 Reply Last reply
        0
        • I imak

          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?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          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...

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups