title: How to autostart windows service after install by sc?
body: <p>I created a batch file for installing service because I need to install my service on PC don't have Visual Studio.</p>
  
  <p>Content of batch file:</p>
  
  <pre><code>@echo OFF
  echo Installing service...
  sc create "MyService" binpath= %~dp0\MyService.exe start= auto
  echo Installing service complete
  pause
  </code></pre>
  
  <p>And I need to autostart MyService after install, so I make this code:</p>
  
  <pre><code>private void svInstaller_AfterInstall(object sender, InstallEventArgs e)
  {
      ServiceController sc = new ServiceController(svInstaller.ServiceName);
      sc.Start();
  }
  </code></pre>
  
  <p>Don't any problem if I installing my service by Visual Studio Command Prompt with InstallUtil.
  When I install service by batch file, my service didn't autostart.</p>
  
  <p>How to possible to auto start my service after install by batch file?</p>
  
  <p><strong>Update:</strong> Thanks Sam Denty's answer, I problem is resolved.<br/>
  But I have another question: <strong>When I install my service by sc, my code in AfterInstall function do not work?</strong></p>