Introduction
This blog describes simple way to install Windows Service in local machine and remove windows service from local machine.
Getting Started
windows service installation 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
- Make sure you have added Service Installer to your service application .
- 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.
- Click the background of the designer to select the service itself, rather than any of its contents.
- 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.
- 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.
- To determine how your service will be started, click the ServiceInstaller component and set the StartType(Manual, Automatic, Disabled) property to the appropriate value.
- Click the ServiceProcessInstaller component and set the appropriate property values.
Steps to Install Windows Service
- Build your service application with release mode and take the builds int to a path, this will be path of your installed windows service.
- Open Developer Command Prompt execute the InstallUtil.exe with command
- The syntax of command is:
C:\>"Full path of installutil.exe" "Full path of service.exe"
- 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"
- Use the above command and press Enter
Steps to Uninstall Windows 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