How to: Install and uninstall Windows services

Warning

This documentation isn't for the latest version of Windows Service. For the latest content on Windows Services using BackgroundService and the Worker Service template, see:

If you're developing a Windows service with .NET Framework, you can quickly install your service app by using the InstallUtil.exe command-line utility or PowerShell. Developers who want to release a Windows service that users can install and uninstall can use the free WiX Toolset or commercial tools like Advanced Installer, InstallShield, and others. For more information, see Create an installer package (Windows desktop).

Warning

If you want to uninstall a service from your computer, don't follow the steps in this article. Instead, find out which program or software package installed the service, and then choose Apps in Settings to uninstall that program. Many services are integral parts of Windows; if you remove them, you might cause system instability.

To use the steps in this article, you first need to add a service installer to your Windows service. For more information, see Walkthrough: Creating a Windows service app.

You can't run Windows service projects directly from the Visual Studio development environment by pressing F5. Before you can run the project, you must install the service in the project.

Tip

You can use Server Explorer to verify that you've installed or uninstalled your service.

Install using InstallUtil.exe utility

  1. From the Start menu, select the Visual Studio <version> directory, then select Developer Command Prompt for VS <version>.

    The Developer Command Prompt for Visual Studio appears.

  2. Access the directory where your project's compiled executable file is located.

  3. Run InstallUtil.exe from the command prompt with your project's executable as a parameter:

    installutil <yourproject>.exe
    

    If you're using the Developer Command Prompt for Visual Studio, InstallUtil.exe is already on the system path. Otherwise, you can add it to the path, or use the fully qualified path to invoke it. This tool is installed with the .NET Framework in %WINDIR%\Microsoft.NET\Framework[64]\<framework_version>.

    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.

Uninstall using InstallUtil.exe utility

  1. From the Start menu, select the Visual Studio <version> directory, then select Developer Command Prompt for VS <version>.

    The Developer Command Prompt for Visual Studio appears.

  2. Run InstallUtil.exe from the command prompt with your project's output as a parameter:

    installutil /u <yourproject>.exe
    
  3. After the executable for a service is deleted, the service might still be present in the registry. If that's the case, use the command sc delete to remove the entry for the service from the registry.

Install using PowerShell

  1. From the Start menu, select the Windows PowerShell directory, then select Windows PowerShell.

  2. Access the directory where your project's compiled executable file is located.

  3. Run the New-Service cmdlet with a service name and your project's output as arguments:

    New-Service -Name "YourServiceName" -BinaryPathName <yourproject>.exe
    

Uninstall using PowerShell

  1. From the Start menu, select the Windows PowerShell directory, then select Windows PowerShell.

  2. Run the Remove-Service cmdlet with the name of your service as an argument:

    Remove-Service -Name "YourServiceName"
    

    Note

    You must have PowerShell 6 or later to use this cmdlet. For information about updating PowerShell, see Installing PowerShell on Windows.

  3. After the executable for a service is deleted, the service might still be present in the registry. If that's the case, use the command sc delete to remove the entry for the service from the registry.

    sc.exe delete "YourServiceName"
    

See also