Thursday, April 2, 2009

Windows Service Installer

Creating Sample Service

Bellow are the steps required to create the sample .NET Service

  1. Startup Visual Studio, and select the C Sharp node under Project Types. Under Templates, select Windows Service and name the project MyWinService.
  2. Under Solution Explorer, select the file name Service1.cs, and change it to MyWinService.cs under Properties section.
  3. Open MyWinService.cs in design mode. Right-Click on the design area and choose Add Installers. This will place two components called ServiceProcessInstaller1 and ServiceInstaller1 onto the design area.
  4. Select ServiceInstaller1, change its name to MyWinServiceInstaller. Also change the ServiceName from Service1 to MyWinService.
  5. Select ServiceProcessInstaller1, and change its name to MyWinServiceProcessInstaller.

Create Setup Project

  1. On the Solution node right click and Add-> New Project.
  2. In Add New Project dialog, navigate to Project Types->Other Project Types->Setup and Deployment and select Template Setup Project. Set Name to MyWinServiceInstaller.
  3. Right click on MyWinServiceInstaller and select Add->Project Output.
  4. In Add Project Output Group dialog select MyWinService Project in the drop down list and select Primary output.
  5. Create Custom action by right clicking on MyWinServiceInstaller->View->Custom Actions. The Custom Actions tab will appear. Custom actions will install/uninstall the service instead of manually running installutil.
  6. Right click on Install->Add Custom Action. In the Select Item in Project dialog navigate to Application Folder->Primary output from MyWinService.
  7. Repeat step 6 for uninstall.

Build install project and install msi.

1 comment:

  1. Thanks! This post helped me a lot and couldn't be simpler to understand :)

    ReplyDelete