Run an application as a Windows Service

Version: 10.4

A Windows Service is an executable application that the operating system runs in the background. It does not require a logged-in user session to run. In Windows, the Service Control Manager (SCM) manages all Windows service processes. The SCM is a special system process that starts and stops the services. 

You can configure a Sitecore Host application to run as a Windows Service by passing the -s or --service argument to the host application.

Note

Currently this feature is only compatible with Sitecore Host applications that target the full .NET framework. If not, the -s option is not available.

Running the above command from anywhere other than a Windows Service (for example, from the command line) results in the following error message:

Cannot start service from the command line or a debugger. A Windows Service must first be installed (using installutil.exe) and then started with the ServerExplorer, Windows Services Administrative tool or the NET START command.

Install a Sitecore Host application as a Windows Service

Use the following  PowerShell command to install a new service:

RequestResponse
New-Service -Name "ExampleService" -DisplayName "Example Service" -Description "An Example Service" -StartupType Manual -BinaryPathName "Path-To-App.exe --service"

Start the service

To start the service, use the following Powershell command:

RequestResponse
Start-Service -Name "ExampleService"

Stop the service

To stop the service, use the following Powershell command:

RequestResponse
Stop-Service -Name "ExampleService"

Uninstall the service

To uninstall the service, use the following Powershell command:

RequestResponse
sc.exe Delete "ExampleService"

Do you have some feedback for us?

If you have suggestions for improving this article,