title: Set Service Start Parameter using Topshelf
body: <p>I have a service with multiple instances with different parameters for each instance, at the moment I'm setting these parameters manually (in another code to be exact) to Image Path of the service in Registry (e.g. <code>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\MyService$i00</code>). so our service installation is done in two steps. </p>
  
  <p>I'm really interested to merge these steps in Topshelf installation for example like</p>
  
  <pre><code>MyService.exe install -instance "i00" -config "C:\i00Config.json"
  </code></pre>
  
  <h3>First Try</h3>
  
  <p>I tried <code>AddCommandLineDefinition</code> from TopShelf but it seems it only works during installation and running through console not the service itself (will not add anything to service Image Path).</p>
  
  <h3>Second Try</h3>
  
  <p>I tried to see if its possible to do this with <code>AfterInstall</code> from Topshelf without any luck. here is a test code to see if it going to work or not (but unfortunately Topshelf overwrites the registry after <code>AfterInstall</code> call).</p>
  
  <pre><code>HostFactory.Run(x =&gt;
          {
              x.UseNLog();
              x.Service&lt;MyService&gt;(sc =&gt;
              {
                  sc.ConstructUsing(hs =&gt; new MyService(hs));
                  sc.WhenStarted((s, h) =&gt; s.Start(h));
                  sc.WhenStopped((s, h) =&gt; s.Stop(h));
              });
  
              x.AfterInstall(s =&gt;
              {
                  using (var system = Registry.LocalMachine.OpenSubKey("SYSTEM"))
                  using (var controlSet = system.OpenSubKey("CurrentControlSet"))
                  using (var services = controlSet.OpenSubKey("services"))
                  using (var service = services.OpenSubKey(string.IsNullOrEmpty(s.InstanceName)
                      ? s.ServiceName
                      : s.ServiceName + "$" + s.InstanceName, true))
                  {
  
                      if (service == null)
                          return;
  
                      var imagePath = service.GetValue("ImagePath") as string;
  
                      if (string.IsNullOrEmpty(imagePath))
                          return;
  
                          var appendix = string.Format(" -{0} \"{1}\"", "config", "C:\i00config.json"); //only a test to see if it is possible at all or not
                          imagePath = imagePath + appendix;
  
  
                      service.SetValue("ImagePath", imagePath);
                  }
              });
  
              x.SetServiceName("MyService");
              x.SetDisplayName("My Service");
              x.SetDescription("My Service Sample");
              x.StartAutomatically();
              x.RunAsLocalSystem();
              x.EnableServiceRecovery(r =&gt;
              {
                  r.OnCrashOnly();
                  r.RestartService(1); //first
                  r.RestartService(1); //second
                  r.RestartService(1); //subsequents
                  r.SetResetPeriod(0);
              });
          });
  </code></pre>
  
  <p>I couldn't find any relevant information about how it can be done using TopShelf so the question is, is it possible to do this with TopShelf?</p>