title: How to autostart windows services in C#
body: <p>I already made a windows service that should autostart when Windows starts up, but for some reason It does not work. I used the code below:</p>
  
  <pre><code>private void serviceInstaller1_AfterInstall(object sender, InstallEventArgs e)
      {
          using (ServiceController sc = new ServiceController(serviceInstaller1.ServiceName))
          {
              sc.Start();
          }
      }
  </code></pre>
  
  <p>After install the service using InstallUtil.exe it starts automatically, but if I make a restart it does not start even when the configuration in the Service Manager is "Automatic".</p>
  
  <p>I already tried changing for "Automatic (Delayed Start) " but nothing changed.</p>
  
  <p>I will appreciate some advice.</p>
  
  <p>Sorry for my poor english, I'm not a native.</p>
  
  <p>Thanks</p>