Solved

Multiple Installer for Windows Service written in .Net

Posted on 2014-03-20
4
1,156 Views
Last Modified: 2014-05-06
Dear Experts,

I have a windows service that is written in vb.net/.net 4.0. This is how I use the windows service.

1. I install seven instances of the same service on multiple servers. Each service reads an application settings value called process id (one value from 1 through 7). When the service processes data, it reads data belonging to that specific process id.  That way I can run seven instances of the same service independently without any instance stepping any other instance.

2. The system administrators at my company want seven different installer (.msi) files, one for each windows service. So I have seven copies of the same windows service project. Each service has its own service installer and service process installer. Also, each windows service project has its own setup project. So I set the configuration value (process id) and service name for each windows service and execute a build for each service.

As you can see, this is not the most efficient way of implementing this. So I looked at this solution:
http://www.codeproject.com/Articles/21320/Multiple-Instance-NET-Windows-Service

While I was able to implement this fairly easily, I cannot use installUtil (system administrators do not want to use it). I still want to build multiple installer (.msi) files but not have to keep multiple copies of code. Also, the seven services are installed across three servers and so I cannot package all seven services in one .msi file.

Is there a way I could keep one copy of the service and generate seven (or more instances controlled by a script or configuration file) different .msi files, one for each instance of the service?

My ideal solution will be to have some kind of a script that will accept number of services as a parameter and then generate one .msi file for each instance of the service. I am leaning towards PowerShell but don't know how difficult it will be in PowerShell. Also, I'd like to keep just one copy of the windows service code.

Sorry my question's description is a bit long but I wanted to make sure I document all the facts.

Thanks for your help.
0
Comment
Question by:shekhar_shashi
4 Comments
 
LVL 16

Assisted Solution

by:SriVaddadi
SriVaddadi earned 50 total points
ID: 39945225
I don't think you would need multiple msi packages. You could prompt for the service name (which should be unique in order to install multiple service instances) through the installer and write it to the config file in your installer code.

You program always reads the service name from the configuration file as shown in the link you posted.
0
 
LVL 7

Accepted Solution

by:
HaiFai earned 450 total points
ID: 40043882
Hi

How about if you make main entry and add installer to service it self ?
so that you could just share exe file and use it with parameters like
service.exe /install /4
so it will install 4 services
something like this what i use

 Try
            If args.Length > 0 Then
                Select Case args(0)
                    Case Is = "/u", "/uninstall", "-u"
                        System.Configuration.Install.ManagedInstallerClass.InstallHelper(New String() {"/u", Assembly.GetExecutingAssembly().Location})
                        MsgBox("Service uninstalled sucessfully!", MsgBoxStyle.Information Or MsgBoxStyle.OkOnly, "Self Installing Service")
                    Case "/i", "/install", "-i"
                        System.Configuration.Install.ManagedInstallerClass.InstallHelper(New String() {Assembly.GetExecutingAssembly().Location})
                        MsgBox("Service installed sucessfully! Please start it from the Services control panel.", MsgBoxStyle.Information Or MsgBoxStyle.OkOnly, "Self Installing Service")
                    Case "/h", "/options", "/o", "/help", "-h"
                        MsgBox("parameters " & vbCrLf & "service.exe /i or /install will install serverce" & vbCrLf & "service.exe /u or /uninstall will uninstall service")
                        ' My.Forms.ApplicationOptionsForm.ShowDialog()
                    Case Else
                        MsgBox("Just because I don't care doesn't mean I don't understand. :Homer Simpson")
                End Select
            Else
                Dim ServicesToRun() As System.ServiceProcess.ServiceBase
                ServicesToRun = New System.ServiceProcess.ServiceBase() {New email_exporter_service}
                System.ServiceProcess.ServiceBase.Run(ServicesToRun)
            End If
        Catch ex As Exception
            MsgBox("An error occured: " & vbCrLf & vbCrLf & ex.ToString, MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly, "Self Installing Service")
        End Try

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now