When my application starts I run some code to encrypt certain connection strings in my config file(s). The config files are located in the installation directory in "C:\Program Files (x86)\myapplication".
When the user starting the application is not an admin (which is always the case) the application gives an error because it cannot edit a file in program files if not an admin.
I have some difficulties in trying to impersonate an admin user. I tried some different approaches I found on the net but with no success.
I hope someone can provide me with a way of achieving this.
What I DON'T want is a prompt for an admin user to login, or change the config file's manifest to require admin privileges to continue. I DO want to temporarily gain admin access (impersonate admin) to encrypt\modify the config file and then continue as the real user.