High-Performance Development - C#, VB, SQL, ASP.NET

Slogan Text

How to Install Windows Service

The "old" way of installing and uninstalling Windows service was by using the InstallUtil tool.

The new approach is to create a ProjectInstaller.vb (or ProjectInstaller.cs) in your Visual Studio project.

The InstallUtil tool installs and uninstalls Windows Services.

  1. Using Notepad or your favorite text editor create a new file named Install.bat.
    • Note: Visual Studio editor inserts funky characters at the beginning of new text files. Use Notepad.
  2. Add a line to run InstallUtil. See example below.
  3. Change <MyServiceProject> to your Visual Studio project path.
  4. Change <MyService> to your service executable.
  5. Change the Microsoft version directory to the framework you are using on your system.
    • For example, you might need to change v4.0.30319 to v2.0.50727.
  6. Add a line to start the service with NET START <MyService>.
  7. Change <MyService> to your service executable.
  8. Save and close Notepad.
  9. See Final Steps below.

C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\installutil "c:\<MyServiceProject>\Bin\Debug\<MyService>.exe"
NET START <MyService>

How to Uninstall Windows Service

  1. Using Notepad create a new file named Uninstall.bat.
  2. Add the lines below.
  3. Change <MyServiceProject> to your Visual Studio project path.
  4. Change <MyService> to your service executable file name.
  5. Save and close Notepad.
  6. See Final Steps

NET STOP <MyService>
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\installutil /u "c:\<MyServiceProject>\Bin\Debug\<MyService>.exe"

Final Steps

  1. Open Command Prompt with Run as Administrator.
  2. Change directory to location of Install.Bat or Uninstall.bat (if needed).
  3. Execute Install.bat or Uninstall.bat at command prompt.

Summary

You may want to add Install.bat and Uninstall.Bat to your Visual Studio project. This would allow you to edit the batch files directly from Visual Studio.

Keep in mind this method of installing and uninstalling Windows Service has been superceded in Visual Studio 2010.