Install and Uninstall Windows Service

Kailash Chandra Behera | Wednesday, March 28, 2018

Introduction

Demonstrates how to install or Uninstall windows services of different revision using command prompt

Getting Started

Installing Windows service is as simple as installing software, but is bit difference from software installation.

InstallUtil.exe utility is required to install Windows Service and you will find this utility from below path if installed Visual Studio. This utility is varying for a different version of the .NET framework of Visual Studio and System, you need to select correct utility based on your framework version in which you have built your Windows Service.

Microsoft provides variety of InstallUtil.exe which based on .NET FRAMEWORK, following below are the path of InstallUtil.exe for different version.

Utility Paths: For 32-bit Machine

.Net Framework 4 and above: C:\Windows\Microsoft.NET\Framework\v4.0.30319
.Net Framework 3.5: C:\Windows\Microsoft.NET\Framework\v3.5
.Net Framework 3.0: C:\Windows\Microsoft.NET\Framework\v3.0
.Net Framework 2.0: C:\Windows\Microsoft.NET\Framework\v2.0.50727
.Net Framework 1.0: C:\Windows\Microsoft.NET\Framework\v1.0.3705
.Net Framework 1.1: C:\Windows\Microsoft.NET\Framework\v1.1.4322

Utility Paths: For 64-bit Machine

.Net Framework 4 and above: C:\Windows\Microsoft.NET\Framework64\v4.0.30319
.Net Framework 3.5: C:\Windows\Microsoft.NET\Framework64\v3.5
.Net Framework 3.0: C:\Windows\Microsoft.NET\Framework64\v3.0
.Net Framework 2.0: C:\Windows\Microsoft.NET\Framework64\v2.0.50727
.Net Framework 1.0: C:\Windows\Microsoft.NET\Framework64\v1.0.3705
.Net Framework 1.1: C:\Windows\Microsoft.NET\Framework64\v1.1.4322

Precaution

  1. Make sure you have added Service Installer to your service application .
  2. If you not added go to Solution Explorer. In Solution Explorer, access Design view for the service for which you want to add an installation component.
  3. Click the background of the designer to select the service itself, rather than any of its contents.
  4. With the designer in focus, right-click, and then click Add Installer. A new class, ProjectInstaller, and two installation components, ServiceProcessInstaller and ServiceInstaller, are added to your project, and property values for the service are copied to the components.
  5. Click the ServiceInstaller component and verify that the value of the ServiceName property is set to the same value as the ServiceName property on the service itself.
  6. To determine how your service will be started, click the ServiceInstaller component and set the StartType(Manual, Automatic, Disabled) property to the appropriate value.
  7. Click the ServiceProcessInstaller component and set the appropriate property values.
If you have installed Visual Studio in your local machine or server, you can install Windows Service through Developer Command Prompt or you can install using system command Prompt. Go through the below steps to install Windows Service.

Installing Service

  1. Build your service application with release mode and take the builds int to a path, this will be path of your installed windows service.
  2. Open Developer Command Prompt execute the InstallUtil.exe with command
  3. The syntax of command is:
     C:\>"Full path of installutil.exe" "Full path of service.exe"  
    
  4. Here I will install windows service with .NET Framework version 4.0, hence command for my service will be
     C:\>"C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe" "Full path of service.exe"  
    
  5. Use the above command and press Enter

Uninstalling Service

Uninstalling service syntax is same as installation, but little difference like below.
 C:\>C:\Windows\Microsoft.NET\Framework\v4.0.30319\installutil.exe -u "C:\Services\myservice.exe"  

Thanks