How to: Install and uninstall Windows services

If you’re developing a Windows service with the .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 should use InstallShield. For more information, see Create an installer package (Windows client).

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. Note that 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. For more information, see How to use Server Explorer in Visual Studio.

Install your service manually 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 should be 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 your service manually 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 your service manually 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 the with your project's output and a service name as parameters:

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

Uninstall your service manually 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 parameter:

    Remove-Service -Name "YourServiceName"
    
  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