In this article I will explain how to install and uninstall Windows Service using InstallUtil.exe utility from Command Prompt (Line) in C# and VB.Net.
 
Installing the Windows Service using InstallUtil.exe using InstallUtil.exe from Command Prompt (Line)
Once the Windows Service is build you need to find the EXE file in the Debug folder of the Project.
Note: Once the Windows Service is ready for deployment, it is recommended to make use of the Release version of the EXE file instead of the Debug version.
To find the EXE, simply right click Project and select Open Folder in Windows Explorer. Now navigate to Bin => Debug folder and look for the EXE file with name same as that of the project.
Simple Windows Service that runs periodically and once a day at specific time using C# and VB.Net
 
Now copy and build the path in a Notepad (Text) file.
Note: I would recommend to build the command in a Notepad and save it somewhere so that you can use it multiple times.
 
InstallUtil Syntax
InstallUtil /i <Path of Windows Service EXE file>
 
Example:
InstallUtil /i C:\Users\Mudassar\Projects\WindowsService\bin\Debug\WindowsService.exe
Now you need to open Programs => Microsoft Visual Studio 2010 => Visual Studio Tools => Visual Studio Command Prompt (2010).
Note: I am making use of Visual Studio 2010, and hence you need to use the appropriate version installed on your computer. And make sure you are logged in as Administrator. Without Administrator rights it would not allow you to install the Windows Service.
In the command prompt window, copy the InstallUtil command from Notepad and right click in the Command Prompt and click Paste and then press Enter key.
Simple Windows Service that runs periodically and once a day at specific time using C# and VB.Net
Now the Installer will ask for Logon permissions to run the Windows Service and hence you will need to add Windows Username and Password of user who has appropriate permission.
Simple Windows Service that runs periodically and once a day at specific time using C# and VB.Net
 
Note: Username must include Domain Name or the Computer name.
 
After successful installation you will see the following message.
Simple Windows Service that runs periodically and once a day at specific time using C# and VB.Net
You can find the Windows Service in the Services window. In order to open Services window in the Run Command type, services.msc and hit enter.
Simple Windows Service that runs periodically and once a day at specific time using C# and VB.Net
 
Uninstalling the Windows Service using InstallUtil.exe using InstallUtil.exe from Command Prompt (Line)
The syntax for uninstalling a Windows Service is very similar to the installation syntax.
InstallUtil Syntax
InstallUtil /u <Path of Windows Service EXE file>
Example:
InstallUtil /u C:\Users\Mudassar\Projects\WindowsService\bin\Debug\WindowsService.exe
After successful uninstallation you will see the following message.
Simple Windows Service that runs periodically and once a day at specific time using C# and VB.Net