title: Automatically starting a service when the installer finishes
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/212734/how-to-automatically-start-your-service-after-install">How to automatically start your service after install?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a Visual Studio 2008 C# .NET 3.5 service installer project (MSI) running on Windows 7 x64.</p>
  
  <p>I subscribe to the <code>ServiceInstaller.OnAfterInstall</code> notification to start my service when the installation finishes.</p>
  
  <pre><code>[RunInstaller(true)]
  public partial class MyInstaller : Installer
  {
      private System.ServiceProcess.ServiceInstaller my_installer_;
  
      private void InitializeComponent()
      {
          // ...
          this.my_installer_.AfterInstall += new System.Configuration.Install.InstallEventHandler(this.OnAfterInstall);
          // ...
      }
  
      private void OnAfterInstall(object sender, InstallEventArgs e)
      {
          using (System.ServiceProcess.ServiceController svc =
              new System.ServiceProcess.ServiceController("MyService"))
          {
              svc.Start(); // completes successfully
          }
      }
  }
  </code></pre>
  
  <p>Though the function succeeds without exception, my service is never running when the installer finishes.</p>
  
  <p>The event log shows no failures related to service startup and if I go to the services manager, I can start the service manually (or restart the PC and it will start automatically).</p>
  
  <p>What do I need to do to automatically start my service when the installer process finishes?</p>