As a part of service installer using Wix 3.XX, we have been trying to encrypt the connection string. After visiting couple of option on Stackoverflow and some other communities, we have opted to do it in three parts.
- Installer that installs the service in the first part
- At the end of installation it invokes the small executable that picks the location of connection of existing config, encrypts the connection string inside the installation folder and save that config.
- A
.bat
file that clears out the executable for the encryption (basically leaving no traces behind)
All three parts works well with co-ordination, but the encryption executable fails when I try to install that in "Program Files" or "Program Files (x86)" using non-elevated permission (non-admin mode).
Debugging that has given me traces which means that Installer is unauthorized for any such processes.
Here is the code snippet that does it:
1. var fileMap = new ExeConfigurationFileMap { ExeConfigFilename = configPath };
2. var configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);
3. var section = configuration.GetSection(sectionToEncrypt);
4. section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
5. section.SectionInformation.ForceSave = true;
6. configuration.Save(ConfigurationSaveMode.Modified);
Reaching at line 6 it returns me with an error:
System.Configuration.ConfigurationErrorsException
HResult=0x80131902
Inner Exception 1:
UnauthorizedAccessException:
Access to the path 'C:\Program Files (x86)\<AppDirectory>\5tkbxj1v.tmp' is denied.
Any inputs for this will be gracious.
Thanks in advance for the help!