Installing a Windows Service from a separate GUI - how to install .config file along with it?

Posted by Shaul on Stack Overflow See other posts from Stack Overflow or by Shaul
Published on 2010-12-30T10:28:19Z Indexed on 2010/12/30 10:54 UTC
Read the original article Hit count: 234

Filed under:
|

I have written a GUI (call it MyGUI) for ClickOnce deployment on any given client site. That GUI installs and configures a Windows Service (MyService), using the method described here by @Marc Gravell. Here's my code, run from inside MyGUI, which contains a reference to MyService:

using (var inst = new AssemblyInstaller(typeof(MyService.Program).Assembly, new string[] { })) {
  IDictionary state = new Hashtable();
  inst.UseNewContext = true;
  try {
    if (uninstall) {
      inst.Uninstall(state);
    } else {
      inst.Install(state);
      inst.Commit(state);
    }
  } catch {
    try {
      inst.Rollback(state);
    } catch { }
    throw;
  }
}

Take note of that first line: I'm grabbing the assembly for MyService, and installing that. Now, trouble is, the way I've done the deployment, I'm effectively referencing the service's EXE file from the GUI's app folder. So now the service fires up and starts looking for stuff in the MyService.config file, and can't find it, because it's living in someone else's app folder, with only the GUI's MyGUI.config file present.

So, how do I get MyService.config to be available to the service?

© Stack Overflow or respective owner

Related posts about c#

Related posts about windows-services