How do you modify the machine.config using Inno setup?
How do you modify the machine.config using Inno setup?开发者_StackOverflow
I have looked at the documentation and searched google and can't find anything so it makes me feel like I'm asking the wrong question or missing something obvious.
I'm guessing that if it is not obvious then it requires writing a small script to do it. If that is the case, does anyone have a good example?
Edit: machine.config is an xml formatted file used to hold machine level configuration settings for .net applications.
It's been a while since I last used Inno Setup, but I think you have two possibilities. The best, and simplest would be to write a small .exe app that your installer will run after the installation & uninstallation has finished:
[Files]
Source: "mconfig.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall;
[Run]
Filename: "{tmp}\mconfig.exe"; Parameters: "/inst"; Flags: waituntilterminated runhidden
[UninstallRun]
Filename: "{tmp}\mconfig.exe"; Parameters: "/uninst"; Flags: waituntilterminated runhidden
Now, I don't know what language/or what modification you need to do, but a simple c# console-app that does some simple modification of the machine.config could look like this:
using System;
using System.Configuration; // Note: Also add a reference to "System.Configuration.dll"
public class Program {
static void Main(string[] args) {
Configuration config = ConfigurationManager.OpenMachineConfiguration();
if (args.Length > 0) {
if (args[0] == "/inst") {
config.AppSettings.Settings.Add("Test", "Value");
} else if (args[0] == "/uninst") {
config.AppSettings.Settings.Remove("Test");
}
config.Save();
}
}
}
Now, another way to do this is to write this as a function, in the Inno Setup built-in "Pascal scripting" language (if you have previous experience in Turbo/Borland Pascal or Delphi that could be fun to revive). Having tried it myself, I would however recommend against that, since it's quite limited, but may be good for other (less complex) things.
Hope this helps!
精彩评论