title: How do I pass command line parameters to an MSI file for a Windows Service
body: <p>I am writing a windows service and I want to pass command line parameters for the MSI installer. The end goal is to use these command line parameters for the Service to know how to operate.</p>
  <p>I have added an installer class as below :</p>
  <pre><code>using Quicktech.QuickteckAgentUpdaterServices.Classes;
  using System;
  using System.Collections.Specialized;
  using System.ComponentModel;
  using System.Configuration.Install;
  using System.ServiceProcess;
  
  namespace Quicktech.QuickteckAgentUpdaterServices
  {
      [RunInstaller(true)]
      public partial class ProjectInstaller : System.Configuration.Install.Installer
      {
          public InstallContext myInstallContext;
  
          public ProjectInstaller()
          {
              InitializeComponent();
          }        
  
          private void serviceInstaller1_AfterInstall(object sender, System.Configuration.Install.InstallEventArgs e)
          {
              ServiceInstaller serviceInstaller = (ServiceInstaller)sender;                        
  
              using (ServiceController sc = new ServiceController(serviceInstaller.ServiceName))
              {
                  sc.Start();
                  
                  if (Context.Parameters.Count == 0)
                  {
                      Console.Write(&quot;0&quot;);
                      Global.FlagForUninstall = false;
                  }
                  else
                  {
                      Console.Write(&quot;1&quot;);
                      Global.FlagForUninstall = bool.Parse(Context.Parameters[&quot;FLAGFORUNINSTALL&quot;].ToString());
                  }                    
              }
          }
  
          private void serviceProcessInstaller1_BeforeInstall(object sender, InstallEventArgs e)
          {
              StringDictionary myStringDictionary = myInstallContext.Parameters;
              if (myStringDictionary.Count == 0)
              {
                  Console.Write(&quot;0&quot;);
                  Global.FlagForUninstall = false;
              }
              else
              {
                  if (myInstallContext.IsParameterTrue(&quot;FlagForUninstall&quot;) == true)
                  {
                      Console.Write(&quot;1&quot;);
                      Global.FlagForUninstall = bool.Parse(myInstallContext.Parameters[&quot;FlagForUninstall&quot;].ToString());
                  }
              }           
          }
      }
  }
  </code></pre>
  <p>and I configured the Custom Actions as below :</p>
  <p><a href="https://i.stack.imgur.com/wu6qe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wu6qe.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/6hSzP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6hSzP.png" alt="enter image description here" /></a></p>
  <p>I call the install as below :</p>
  <pre><code>c:\&gt;msiexec.exe /i &quot;QuickteckAgentUpdaterServiceSetup-x64.msi&quot; /l*v &quot;c:\temp\out.txt&quot; FlagForUninstall=True
  </code></pre>
  <p>When I run the service and look at the procedure called on the On_Start event :</p>
  <p>I have the following code :</p>
  <pre><code>if (!Global.FlagForUninstall)
  </code></pre>
  <p>this is set in the installer class. What am I doing wrong? Why can I not see the command line arguments?</p>
  <p>When I look at the Log File, I see the following :</p>
  <pre><code>Property(S): FLAGFORUNINSTALL = true
  </code></pre>
  <p>It looks like the command line parameters are working, but I am not able to set the FlagForUninstall variable and use it in the execution of the service.
  Can anyone point me in the right direction?
  I do not need to set the GLOBAL.FlagforUninstall. If there is any other way to access the Installer.Context properties I am willing to go that route.</p>