Multiple instances of a Windows Service

M

MW

Hi all,

I have written a windows service application and setup project to
install/deinstall my service.

There is a requirement to run one more instance of the same service with
different set of configurations and connecting to a different database. Both
the services will run on the same box. Is it possible to do that?

Someone suggested that there are entries in the windows registry that can be
duplicated to achieve it. I want to first investigate if there is a better
option within .NET. If not, then atleast know what entries should be
duplicated and what values should be changed before I go ahead.

Any thoughts will be most welcome

TIA
Wazir
 
L

Lee Gillie

There are a number of extra fun things you can do with your service
registry settings. Code to add these should be in your installer when
installing. You have to look for them and remove them when
uninstalling if you want your MSI to be people friendly.

- Lee
 
M

MW

Thanks for your post Lee.

I did get around to solving my problem without having to mess around with my
service registry settings. For those interested, this is how I did it.

Since I wanted to create two instances of my service I wanted to identify
them by their service names. Hence I created another constructer with the
service name as a parameter. Based on the sevice names I could look up
different configuration files for each.

Public Sub New(ByVal sServiceName As String)
MyBase.New()
' This call is required by the Component Designer.
InitializeComponent()

' Add any initialization after the InitializeComponent() call
Me.CanShutdown = True
Me.ServiceName = sServiceName
End Sub

I then edited the Main sub of the service class

' The main entry point for the process
<MTAThread()> _
Shared Sub Main()
Dim ServicesToRun() As System.ServiceProcess.ServiceBase

' More than one NT Service may run within the same process. To add
' another service to this process, change the following line to
' create a second service object.

ServicesToRun = New System.ServiceProcess.ServiceBase() {New
myService("Service1"), New myService("Service2")}
System.ServiceProcess.ServiceBase.Run(ServicesToRun)
End Sub

Step three.- Added another ServiceInstaller to my projectInstaller for the
second instance and the set the displayname and servicename properties
appropriately

Create new builds for the service project and the setup project and
installed the msi. Service Control Manager showed both services and both
started successfully.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top