How to install a windows service using Windows command prompt

By FoxLearn 11/9/2024 4:36:14 AM   53
To install a Windows service using the Command Prompt, you can use the installutil or sc command.

How to install a Windows service using the command line?

To install a Windows service using installutil.exe, follow these steps

Open Command Prompt as Administrator, then navigate to the installutil.exe in your .net folder

For .NET Framework 4.x, the path is typically:

C:\Windows\Microsoft.NET\Framework\v4.0.30319

Next, Use installutil.exe to install the service:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe c:\yourservice.exe

For 64bit apps, use below

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\installutil.exe c:\yourservice.exe

This will register and install the service on your system. To start the service, you can use the sc start command, or manage it through the Services management console (services.msc).

You can also use the sc command to install the service.

sc create <ServiceName> binPath= "<PathToExecutable>" [options]

If you want to install a service called MyService and the executable is located at C:\Path\To\YourService.exe, the command would look like this:

sc create MyService binPath= "C:\Path\To\YourService.exe"

You can specify additional parameters when creating the service, such as the service's start type (manual, automatic, or disabled). Here's an example of how to set the service to start automatically

sc create MyService binPath= "C:\Path\To\YourService.exe" start= auto
  • start= auto: Sets the service to start automatically when the system boots.
  • start= demand: Sets the service to start manually (you will have to start it manually).
  • start= disabled: Disables the service.

Once the service is installed, you can start it using the following command:

sc start MyService

To check if the service has been installed and is running, you can use the sc qc command to query the configuration of the service:

sc qc MyService