How to Install or Uninstall a Windows Service in C#?
Last Updated :
16 Oct, 2022
Windows Services is a core component of the Microsoft Windows NT operating system that allows the creation and regulation of processes. Windows Services can start without user intervention and may continue to run long after the user has logged off. Windows services run in the background of the OS and usually start from the OS startup. Windows services are written in .NET using C# Programming Language. Therefore the language enables us to install/uninstall any Windows service at demand. In this article, we will learn how to install or uninstall a windows service in C#.
Initial Download Of Microsoft .NET Framework
For this process, we need to have Microsoft .NET Framework installed in the Operating System. If you have C# Installed then you would already have it, otherwise, you could download and install it from Microsoft Website.
For demonstration, we would be installing a service named tor.exe into the OS, which is located at the path C:\tor.exe.
Find the absolute path of the directory where InstallUtil.exe is present. Which is usually present in the C drive. In our case, the file is located at C:\Windows\Microsoft.NET\Framework\v2.0.50727.
The path will be different for different versions of .NET. You may just want to search on your machine where InstallUtil.exe is stored. For example:
- For the 32-bit version of the .NET Framework 4 or 4.5 and later, if your Windows installation directory is C:\Windows, the default path is C:\Windows\Microsoft.NET\Framework\v4.0.30319\InstallUtil.exe.
- For the 64-bit version of the .NET Framework 4 or 4.5 and later, the default path is C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe.
Process
For this purpose, we would be using the InstallUtil.exe preset in the .NET Framework. The goal of the util is to install/uninstall any services in the operating system. Firstly we would be using it to install a service.
Installing the Service
Step 1: Start Windows Command Processor (cmd.exe) by typing cmd in the start menu and selecting the open/run option. A new window would have appeared, similar to the image shown below.
Step 2: Now, go to the parent folder of the installutil.exe. For example, its parent directory would be at C:\Windows\Microsoft.NET\Framework\v2.0.50727.
Run Command:
cd C:\Windows\Microsoft.NET\Framework\v2.0.50727.
Step 3: To install the service you have to run the command with the following structure:
Command Structure:
InstallUtil.exe “_Path_to_the_Service_”
Where the _Path_to_the_Service_ is the location of the service which we are willing to install. For example, C:\tor.exe. So the command is:
Run Command:
Installutil.exe “C:\tor.exe”
Step 4: Now, the service tor has been started and it could be confirmed by the task manager. Type Task manager, and in the search box, you will find a file name tor into your system.
Uninstalling the Service
Now, we will learn how to uninstall the service. For that, we would use the Uninstall Switch \U. Therefore, the syntax for uninstalling a Service using C# is:
Run Command:
Installutil.exe \U "C:\test.exe".
Similar Reads
How to Install Visual C++ on Windows?
In this article, we will discuss the process of installing Visual C++ on Windows. Visual C++ is part of the general "C suite" of programming languages often used for many different types of development projects. The full name of the product is Microsoft Visual C++, which is sometimes abbreviated as
1 min read
How to uninstall OpenCV in Windows?
OpenCV (Open Source Computer Vision Library) is a powerful open-source computer vision and machine learning software library. While it provides incredible functionality for image processing and analysis, there may come a time when you need to uninstall it from your Windows system. This article will
1 min read
How To Uninstall Jenkins On Windows And Linux ?
Jenkins is a popular open-source server automation that is used for continuous integration and continuous delivery (CI/CD) for building, deploying, and automating projects. Jenkins is one of the most popular tools used by DevOps to facilitate server automation tasks. Jenkins is highly extensible and
4 min read
How to Uninstall an Instance of SQL Server?
SQL Server is a Relational Database Management system that was developed and marketed by Microsoft. In this article, we will look into how to uninstall an instance of SQL Server setup: Prerequisites:To uninstall SQL Server, you need to have local administrator permissions.Back up your data. You coul
2 min read
How to Install SQL Server Agent on Windows?
SQL Server Agent is a component of Microsoft SQL Server. It schedules jobs and handles other automated task on a database.This windows service can automatically start when we boot up the system or set it up manually. SQL Server Agent enables us to automate all the task which are repetitive in nature
3 min read
How to Uninstall SCCM Client From Windows On-Premises Server?
SCCM Client agent is application software used for configuration management on the on-premise environment. In this article, we will show step-by-step instructions on removing the SCCM client or uninstalling the Microsoft System Center Configuration Management Client from your Windows Client or Windo
2 min read
How to Install OSSEC Agent on Windows?
OSSEC is an open-source Host dependent Intrusion detection software. OSSEC could be understood as Operating System Security. OSSEC is available for all major operating systems such as Linux, Windows, OS X, Solaris, and many other UNIX-based systems. OSSEC performs various operations to ensure securi
3 min read
How to Install SQL Server Client on Windows?
The Client / Server Application is a computer program that allows users to access what is stored on the server. Of course, both computers can be workstations running the same type of operating system. In most network environments, the server contains a database that requires users to access this dat
2 min read
How to Stop MySQL Server on Windows and Linux?
MySQL is one of the most popular open-source relational database management systems. Whether we are managing a small development setup or a production environment knowing how to start and stop MySQL servers is essential. In this guide, we will learn about the steps to start and stop MySQL servers on
3 min read
How to Install and Use NVM on Windows
NVM or Node Version Manager is a command-line tool that allows developers to manage multiple versions of Node.js on a single machine. This function offers the flexibility to work on different projects and versions of Node.js. In this guide, we'll walk you through the steps to install and use NVM on
3 min read