The most 'elegant' way I've found doing that is using some raw xml, which includes the entire startup section. So while it might not be the most 'correct' way, it is still better than manual edit of the config file IMO.
Here is a working code example for editing the config file from within the same executable (you might need to provide the path in OpenExeConfiguration to do so from your installer):
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var sec = config.Sections["startup"];
sec.SectionInformation.SetRawXml("<startup useLegacyV2RuntimeActivationPolicy=\"true\"><supportedRuntime version=\"v4.0\" sku=\".NETFramework,Version=v4.0\" /></startup>");
config.Save(ConfigurationSaveMode.Modified);