title: Create a Windows Service installer using .NET Core and command line
body: <p>I created an ASP.NET Core Windows Service application using this sample:
  <a href="https://github.com/dotnet/AspNetCore.Docs/tree/master/aspnetcore/host-and-deploy/windows-service/samples/2.x/AspNetCoreService" rel="noreferrer">https://github.com/dotnet/AspNetCore.Docs/tree/master/aspnetcore/host-and-deploy/windows-service/samples/2.x/AspNetCoreService</a></p>
  <p>Now, I want to install my service using command line, like &quot;MyService.exe -install&quot;. I know that if I use &quot;sc create&quot; will works, but I want to install using my own application to install and configure the service as I want.</p>
  <p>I found a sample using Toshelf package, but I am using WebHostBuilder and I trying to use Custom Service configuration. The service install, but when I start it doesn`t work.</p>
  <p>I am using .NET Core 2.2.</p>
  <p>My configuration:</p>
  <pre><code>HostFactory.Run(x =&gt;
              {
                  x.Service&lt;CustomWebHostService&gt;(sc =&gt;
                  {
                      sc.ConstructUsing(() =&gt; new CustomWebHostService(host));
  
                      // the start and stop methods for the service
                      sc.WhenStarted(ServiceBase.Run);
                      sc.WhenStopped(s =&gt; s.Stop());
                  });
  
                  x.RunAsLocalSystem();
                  x.StartAutomatically();
  
                  x.SetServiceName(&quot;Teste Core&quot;);
                  x.SetDisplayName(&quot;Teste ASP.NET Core Service&quot;);
                  x.SetDescription(&quot;Teste ASP.NET Core as Windows Service.&quot;);
              });
  </code></pre>
  <p>My full source code:
  <a href="https://github.com/rkiguti/dotnetcore.windows-service" rel="noreferrer">https://github.com/rkiguti/dotnetcore.windows-service</a></p>