title: How can I make my .NET Worker Service prompt for credentials on install?
body: <p>On older versions of .NET Framework, when creating a Windows service, you add an installer to the project so that it can be installed using InstallUtil.exe on the command line.  Using this ServiceProcessInstaller class, it was possible to set an empty user so that the installer would actually prompt for credentials for the service during the install.  Here's an example of code I would use in the past to create this installer:</p>
  <pre><code>using System.ComponentModel;
  using System.Configuration.Install;
  using System.ServiceProcess;
  
  namespace DemoWindowsService
  {
      [RunInstaller(true)]
      public class DemoWindowsServiceInstaller : Installer
      {
          private ServiceProcessInstaller _processInstaller;
          private ServiceInstaller _serviceInstaller;
          public WindowsServiceInstaller()
          {
              _processInstaller = new ServiceProcessInstaller();
              _serviceInstaller = new ServiceInstaller();
  
              //set the privileges
              _processInstaller.Account = ServiceAccount.User;
              _processInstaller.Username = null; 
              _processInstaller.Password = null; 
  
              //service name here MUST match the service name set on the service.cs file properties
              _serviceInstaller.ServiceName = &quot;DemoWindowsService&quot;;
              _serviceInstaller.DisplayName = &quot;DemoWindowsService&quot;;
              _serviceInstaller.Description = &quot;just a test service&quot;;
              _serviceInstaller.StartType = ServiceStartMode.Automatic;
              _serviceInstaller.DelayedAutoStart = true;
  
              this.Installers.Add(_processInstaller);
              this.Installers.Add(_serviceInstaller);
          }
      }
  }
  </code></pre>
  <p>Now, when running InstallUtil.exe from the command line to setup this service, it will open a small prompt for the credentials for the service.</p>
  <p>Unfortunately, it appears that in .NET Core, this is no longer possible.  .NET Core now uses Worker Services, which admittedly have a lot of advantages over the old service methods, but I have to install these services using sc.exe, which does not rely on a ServiceProcessInstaller.</p>
  <p>I am aware that I CAN pass the username and password as part of the sc command when I install the Worker service, unfortunately, this does not work... it just results in the service indicating that there was a logon error.  I BELIEVE this has to do with the fact that I'm installing these services on a Windows Server 2012 box, but I'm not certain.</p>
  <p><strong>So my main question is this: is there a way for a Worker Service to prompt for user credentials on install like the old ServiceProcessInstaller used to do? Is this something that can be done on the C# code side, or is there a flag or something I can specify from sc.exe to cause it to prompt for credentials at install time?</strong></p>