Hello,
I've got a program which uses app.config for storing some preferences. The problem is that if the program is installed in C:\program files\<project name> then the changing of preferences is not possible due to the fact that all files in program files\<project name> are available only to administrator.
My code:
public static bool EditKeyPair(string key, string value)
{
bool success = true;
// Open App.Config of executable
System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationCollection settings = config.AppSettings.Settings;
// update SaveBeforeExit
settings[key].Value = value;
if (!config.AppSettings.SectionInformation.IsLocked)
{
//save the file
config.Save(ConfigurationSaveMode.Modified);
Debug.WriteLine("** Settings updated.");
}
else
{
Debug.WriteLine("** Could not update, section is locked.");
success = false;
}
//reload the section you modified
ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name);
return success;
}
The question is: Is there a way how to elevate privileges for this action? Or how else to solve the problem?
Thank you!