Creating Needed Installers for Windows Services

This is not the Actual “Installer”. This is code needed for the Service to operate correctly.

We will get to Installing Later…

Add the Installer Code:

Create a new class file in your project and call it ProjectInstaller.


We wil replace the text in the ProjectInstaller class with the following code:

Version:0.9 StartHTML:0000000100 EndHTML:0000012095 StartFragment:0000000100 EndFragment:0000012095

1 Imports System.ComponentModel

2 Imports System.Configuration.Install


4 <RunInstaller(True)> Public Class ProjectInstaller

5 Inherits System.Configuration.Install.Installer

6 ‘Installer overrides dispose to clean up the component list.


8 <System.Diagnostics.DebuggerNonUserCode()> _

9 Protected Overrides Sub Dispose(ByVal disposing As Boolean)

10 Try

11 If disposing AndAlso components IsNot Nothing Then

12 components.Dispose()

13 End If

14 Finally

15 MyBase.Dispose(disposing)

16 End Try

17 End Sub


19 ‘Required by the Component Designer

20 Private components As System.ComponentModel.IContainer


22 ‘NOTE: The following procedure is required by the Component Designer

23 ‘It can be modified using the Component Designer.

24 ‘Do not modify it using the code editor.


26 <System.Diagnostics.DebuggerStepThrough()> _

27 Private Sub InitializeComponent()

28 Me.ServiceProcessInstaller1 = New System.ServiceProcess.ServiceProcessInstaller

29 Me.ServiceInstaller1 = New System.ServiceProcess.ServiceInstaller


31 ‘ServiceProcessInstaller1


33 Me.ServiceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem

34 Me.ServiceProcessInstaller1.Password = Nothing

35 Me.ServiceProcessInstaller1.Username = Nothing


37 ‘ServiceInstaller1


39 Me.ServiceInstaller1.ServiceName = “NewService1”

40 Me.ServiceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic


42 ‘ProjectInstaller


44 Me.Installers.AddRange(New System.Configuration.Install.Installer() _

45 {Me.ServiceProcessInstaller1, Me.ServiceInstaller1})

46 End Sub


48 Friend WithEvents ServiceProcessInstaller1 As _

49 System.ServiceProcess.ServiceProcessInstaller


51 Friend WithEvents ServiceInstaller1 As _

52 System.ServiceProcess.ServiceInstaller


54 Public Sub New()

55 MyBase.New()


57 ‘This call is required by the Component Designer.

58 InitializeComponent()


60 ‘Add initialization code after the call to InitializeComponent


62 End Sub

63 End Class


This will create the ProjectInstaller class and insert 2 Objects in the designer:


ServiceInstaller1 – Settings: The Service Name, Display Name, description, StartType

ServiceProcessInstaller – Settings: The Account the service will run under


In this example, the settings are set as follows:

ServiceName: NewService1

DisplayName: {blank} 
Description: {blank} 
StartType: Automatic – (will auto start on reboot) 
Account: LocalSystem – (do not need user/password. This will run under System account)


Now we have to build the project.

Services Part 3:>  Build and Install your Service


Building a Setup Package for your Windows Service


If you want to install your Service on other PC’s.  The you want to make an Installer Package.


Build the Setup Package for Your Windows Service:

Prerequisites:  You will need to have .net 3.5 on the target pc.

Choose File> Add> New Project.


At the Add New Project window, Choose:




Right click on Setup1 in Solution Explorer and choose:servicesetup2

At Add Project Output Group,  It will select NewService as the Primary Output.  Just hit OK.

Then you need to tell Setup to Install the Service.  Do this by right clicking Setup1. Choose View > Custom Actions.

Then right click Custom Actions, and choose Add Custom Action.  In Select Item in Project, double click Application Folder:



And choose OK.  It will add one item for each custom Action:


Next, Right click Setup1 and Build.  It will create the Setup Executable in your Projects bin\release folder.

Thats It!.  Run the Setup on the Target computer, and reboot.  It will install and run the Service on reboot.


Programmers – Use your talents to make some money online.  Click Here to Read More

Building and Installing Windows Service Visual Studio 2008


You cannot just hit Run and debug your Windows Service.  That would be really cool, but it is not that hard to get it running.

Build and Install service on your pc:

Choose Build in the Menubar above and choose Build NewService.


This will build your executable in the bin\release folder of your project.  If you try to run the program by itself, it will not run and give you an error.  Instead you have to load the service into your computer by using InstallUtil.exe.

You can run InstallUtil.exe from the VisualStudio Command Prompt.



InstallUtil “PATH_TO_YOUR_EXE.exe”


InstallUtil “PATH_TO_YOUR_EXE.exe” /U

When you run in the command window, you will see alot of text, and at the bottom it should read:

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

Now we have to start the service in Service Manager. –  Right click on My Computer on the Desktop, and choose Manage.



Choose Services and Applications, Services, and New Service:

Right click and Choose Start.

Then Go to EventViewer, Application and you should see a log for service starting, and after 10 seconds you should see your ‘Service Running” log entry

Now you have a running Service.  Don’t forget to stop it.  You dont want to fill your Event log up!  We set the service to Automatic in Part 2, so you may want to uninstall using InstallUtil.exe to remove from your system.

Next we will build a Setup package so you can install easily on computers that are not running Visual Studio.

Services Part 4:>  Build Setup Package for your Windows Service



Programmers – Use your talents to make some money online.  Click Here to Read More

Creating Needed Installers for Windows Services


This is not the Actual “Installer”. This is code needed for the Service to operate correctly.

We will get to Installing and Deploying Later…


Add the Installer Code:

From Service1 designer, right click in the gray area and choose Add Installer.


Another file will be added to your Solution Explorer, called ProjectInstaller.  On this class will be to components in the designer, ServiceProcessInstaller1, and ServiceInstaller1.

Lets configure the Installer:  Click on the listed component and alter the following properties:


  • Account = LocalSystem   (will cause service to run under local service account)
  • serviceProperties1


  • ServiceName = NewService
  • StartType = Automatic     (Whether your service will auto start after reboot)
  • DisplayName =  NewService
  • serviceProperties2

    Now we will Build and Install the service to test it out.

    Services Part 3:>  Build and Install your Windows Service



    Programmers – Use your talents to make some money online.  Click Here to Read More