Developing Windows Service on VB.NET, Part 3: Create Setup Wizard

This entry is part 3 of 4 in the series Developing Windows Service on VB.NET

In this part, I’m going to create an installer project for install my windows service ‘MyService’. The installer wizard helps you to install service easily simply click next, next,.. and finish then you are done. With wizard installation, you can also uninstall the service from Add/Remove Program. If you prefer not to create setup wizard, you can install the service manually, too. You can find the detail about manually install the service at the bottom of this post.

Step-by-step to create setup wizard

Create a setup wizard for install a service

  1. Continue from last part. I’m going to create new project for install the service.
    On ‘MyService’ project, add new project to the existing solution by click File -> Add -> New Project.
    Add new project to the existing solution
  2. On Add New Project page.
    • On Project types, expand Other Project Types -> select Setup and Deployment.
    • On Templates, select Setup Project.
    • Name project as ‘SetupMyService’.
    • Click OK.

    Create a Setup project

  3. You’ll see new project has been added to the existing solution. This is going to be an installer project for ‘MyService’ service.
    New project is added to the existing solution
  4. On Solution Explorer, right click on SetupMyService -> select Add -> Project Output.
    Add new project output
  5. On Add Project Output Group, the project should be ‘MyService’ because this solution only has 1 project. Then, select ‘Primary Output’. Click OK.
    Select MyService as a primary output
  6. Now ‘MyService’ project has been added to the installer project as primary output.
    Primary output is added
  7. Next, I’ll add some custom actions for MyService to be able install and uninstall. On Solution Explorer, right click on ‘SetupMyService’ project -> select View -> Custom Actions.
    View Custom Action
  8. The Custom Actions page was opened. You’ll see folder Install, Commit, Rollback and Uninstall. Next, I’ll add custom actions on each of these. Start with right click on Install and select ‘Add Custom Action’.
    Add new Custom Action on Install
  9. Double click on Application Folders and select ‘Primary output from MyService (Active)’. Click OK.
    Repeat add custom action on the remaining
  10. Repeat adding custom actions on Commit, Rollback and Uninstall. You’ll get custom actions as in the figure below.
    The primary output were added
  11. Next, build the installer project by right click on ‘SetupMyService’ project in solution explorer and select ‘Build’.
    Create Setup Wizard
  12. If there is no error, you will have setup file for install the service.
  13. Navigate to installer project, you’ll see the setup file. There are 2 files, you can choose to use .exe file or .msi file.
  14. Double click the setup file to install ‘MyService’. Follow the instruction to install the service.
  15. When the installation has finished, open services (type ‘services.msc’ in command prompt). Find your service name ‘MyService’. You’ll see that the service hasn’t started yet because the startup type is ‘Manual’. Also, notice that log on as is ‘Local Service’ which are the settings that you have configured in part II.
  16. Right click on the service ‘MyService’. Click Start to start the service. Once the service has started, open application event log in computer management. You’ll see a log tell about the service has been started.
  17. Wait for service running a while and then refresh event log. You see some messages that are generated from MyService in every 10 seconds.
  18. That’s it. You have finished creating an installer for a service.

To manually install the service

You can also install your service manaully by open Visual Studio 2005 Command Prompt and type ‘installutil path-to-your-service.exe’. For instance, I have ‘MyService.exe’ in ‘D:\Projects\MyService\MyService\bin\Debug’ so I would type

‘installutil D:\Projects\MyService\MyService\bin\Debug\MyService.exe’

If there is no error, you will see the message as the figure below.

‘The Commit phase completed successfully.
The transacted install has completed.’

The Commit phase completed successfully

To uninstall the service manaully, simply add /u before path to service as the figure below.

‘installutil /u D:\Projects\MyService\MyService\bin\Debug\MyService.exe’

If there is no error, you will see the mesage
‘The uninstall has completed’.
The uninstall has completed

Series Navigation<< Developing Windows Service on VB.NET, Part 2: Create Windows ServiceDeveloping Windows Service on VB.NET, Part 4: Debug Service >>

8 Comments

  1. Vivek Chauhan December 30, 2008
  2. Stewart July 2, 2009
  3. Tomas July 14, 2009
  4. Sathish December 7, 2010
  5. Sri December 10, 2010
  6. sheetalkumar February 18, 2011
  7. Anto March 16, 2011
  8. linglom March 31, 2011

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.