title: How to pass parameters in windows service from Installer to Main function in Program.cs?
body: <p>I have successfully passed parameters from Installutil to my serviceinstaller but i cannt seem to pass these parameters to the Main(string[ args] function.
  Here is how i am trying to do this ....if there is any better wayto do what i am doing please let me know</p>
  
  <pre><code>    protected override void OnAfterInstall(IDictionary savedState)
      {
          base.OnAfterInstall(savedState);
          string[] args = new string[2];
          args[0] = Context.Parameters["username"];
          args[0] = Context.Parameters["password"];
          new ServiceController(this.dataLoaderServiceInstaller.ServiceName).Start(args);
      }
  </code></pre>
  
  <p>and this is my Program.cs</p>
  
  <pre><code>    static void Main(string[] args)
      {
          // create a writer and open the file
          TextWriter tw = new StreamWriter(@"c:\\bw\\date.txt");
  
          // write a line of text to the file
          tw.WriteLine(args.Length);
  
          // close the stream
          tw.Close();
          ServiceBase[] ServicesToRun;
          ServicesToRun = new ServiceBase[] 
      { 
        new DataloaderService() 
      };
          ServiceBase.Run(ServicesToRun);
      }
  </code></pre>
  
  <p>the length of arugments that i am trying to write is always zero.
  One more question will these parameters still exist after the computer/server restarts for maintenance?
  Thanks in advance. :)</p>