title: Passing parameters into Windows Service
body: <p>I would like to pass 2 ports as a parameter into Windows Service during OnStart. I have seen a few examples around and came across this guide <a href="http://derpturkey.com/c-windows-service-startup-arguments/" rel="nofollow">C# Windows Service Startup Arguments</a>. This code is working when I pass a parameter but when I try to pass two parameters, I got an error <code>Start Service fail 1053</code>. The code is as below.</p>
  
  <pre><code>namespace MyService  
  {
      static class Program
      {
          static void Main(string[] args)
          {
              uint port = uint.Parse(args[1]);
              uint port2 = uint.Parse(args[2]);
  
              ServiceBase[] ServicesToRun;        
              ServicesToRun = new ServiceBase[] 
              { 
                  new MyService(port,port2);
              };
              ServiceBase.Run(ServicesToRun);
          }
      }
  }
  </code></pre>
  
  <p>The code below is my service code.</p>
  
  <pre><code>namespace MyService  
  {
      public partial class MyService : ServiceBase
      {
          public uint Port { get; set; }
          public uint Port2 { get; set; }
  
          public MyService(uint port, uint port2)
          {
              InitializeComponent();
              Port = port;
              Port2 = port2;
          }
  
          protected override void OnStart(string[] args)
          {
              if(args.Length &gt; 0) {
                  Port = uint.Parse(args[1]);
                  Port2 = uint.Parse(args[2]);
              }
  
              // DO STUFF
          }
      }
  }
  </code></pre>
  
  <p>I installed it using the following command.</p>
  
  <pre><code>sc create WindowsService1 binPath= "C:\Users\user\Desktop\abc\Projects\WindowsService1\bin\x86\Debug\WindowsService1.exe --port 3000 --port 2000"
  </code></pre>
  
  <p>and Start using the following command</p>
  
  <pre><code>sc start WindowsService1 --port 3000 --port 2000
  </code></pre>