Below is 2 files that can be used to build multipleservices.exe For install use: installutil /name=MultiTest1 multipleservices.exe installutil /name=MultiTest2 multipleservices.exe
For uninstall use: installutil /u /name=MultiTest1 multipleservices.exe installutil /u /name=MultiTest2 multipleservices.exe --- Per Thygesen MultipleService.cs ------------------------------------- using System; using System.Collections; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.ServiceProcess; namespace MultipleServices { public class MultipleService : System.ServiceProcess.ServiceBase { public MultipleService(string name) { ServiceName = name; } static void Main(string[] args) { // Servicename in args[0] = -s<name> System.ServiceProcess.ServiceBase[] ServicesToRun; ServicesToRun = new System.ServiceProcess.ServiceBase[] { new MultipleService(args[0].Substring(2)) }; System.ServiceProcess.ServiceBase.Run(ServicesToRun); } protected override void OnStart(string[] args) { } protected override void OnStop() { } } } MultipleIntstaller.cs ------------------------------------- using System; using System.Collections; using System.ComponentModel; using System.Configuration.Install; using System.Collections.Specialized; using System.ServiceProcess; namespace MultipleServices { [RunInstaller(true)] public class MultipleInstaller : Installer { private ServiceInstaller serviceInstaller; private ServiceProcessInstaller processInstaller; public MultipleInstaller() { processInstaller = new ServiceProcessInstaller(); serviceInstaller = new ServiceInstaller(); processInstaller.Account = ServiceAccount.LocalSystem; serviceInstaller.StartType = ServiceStartMode.Manual; serviceInstaller.ServiceName = "NoName"; Installers.Add(serviceInstaller); Installers.Add(processInstaller); } protected override void OnBeforeInstall(IDictionary savedState) { base.OnBeforeInstall(savedState); string name = Context.Parameters["name"]; if (name != null) serviceInstaller.ServiceName = name; } public override void Install(IDictionary stateServer) { Microsoft.Win32.RegistryKey system, currentControlSet, services, service, config; base.Install(stateServer); system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System"); currentControlSet = system.OpenSubKey("CurrentControlSet"); services = currentControlSet.OpenSubKey("Services"); service = services.OpenSubKey(this.serviceInstaller.ServiceName, true); service.SetValue("Description", "Multiple Services"); Console.WriteLine("ImagePath: " + service.GetValue("ImagePath")); string imagePath = (string)service.GetValue("ImagePath"); imagePath += " -s" + this.serviceInstaller.ServiceName; service.SetValue("ImagePath", imagePath); config = service.CreateSubKey("Parameters"); config.Close(); service.Close(); services.Close(); currentControlSet.Close(); } protected override void OnBeforeUninstall(IDictionary savedState) { base.OnBeforeUninstall(savedState); string name = Context.Parameters["name"]; if (name != null) serviceInstaller.ServiceName = name; } public override void Uninstall(IDictionary stateServer) { Microsoft.Win32.RegistryKey system, currentControlSet, services, service; base.Uninstall(stateServer); system = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("System"); currentControlSet = system.OpenSubKey("CurrentControlSet"); services = currentControlSet.OpenSubKey("Services"); service = services.OpenSubKey(this.serviceInstaller.ServiceName, true); service.DeleteSubKeyTree("Parameters"); service.Close(); services.Close(); currentControlSet.Close(); } } } ----- Original Message ----- From: "Lam, Patrick" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, May 03, 2002 10:40 AM Subject: [DOTNET] Multiple instances of the same windows service > Basically, I need to do the same thing as Per. i.e., I want N different > services, all pointing to the same executable (which implements the same set > onStart, onStop, etc.) > > I don't quite get however, what to do about setting Service Name in the > Main() of the Service's VB file and its associated ProjectInstaller (it this > what is being talked about here??). > > What I mean is that I have a service, called MyService defined within > MyService.vb (one instance, one name for now), and such a Service has a Main > method which gas the following > > ServicesToRun = New System.ServiceProcess.ServiceBase() {New > MyService ()} > System.ServiceProcess.ServiceBase.Run(ServicesToRun) > > Next, I have my ProjectInstaller.vb (added by clicking on the link Add > Installer) in the service's design view. It has the following line: > > Me.ServiceInstaller1.ServiceName = "MyService" > > 'ProjectInstaller > ' > Me.Installers.AddRange(New System.Configuration.Install.Installer() > _ > {Me.ServiceProcessInstaller1,Me.ServiceInstaller1, }) > > Finally, the Project's Property is define to have output of type > WindowsApplication, with a startup object being MyService. > > OK, I get I could read config files, etc from ProjectInstaller.vb, but how > could that "create and change" the service name in MyService.vb and add the > appropriate installer accordingly? > > > >Date: Tue, 26 Feb 2002 13:29:09 -0800 > >Reply-To: dotnet discussion <[EMAIL PROTECTED]> > >Sender: dotnet discussion <[EMAIL PROTECTED]> > >From: Scott Boston <[EMAIL PROTECTED]> > >Organization: spacehug.com > >Subject: Re: Multiple instances of the same windows service > >In-Reply-To: <[EMAIL PROTECTED]> > >Content-Type: text/plain; charset="US-ASCII" > > > >Yes, then you can set the service name in the registry (or a local > >configuration file) from your installer class, since the installer is > >aware of the service name. Then your Main() method in the service > >itself can retrieve that value from wherever you stored it, and set the > >ServiceBase.ServiceName. I do that by passing it into the service > >constructor, and setting it there. > > > > -----Original Message----- > > From: dotnet discussion [mailto:[EMAIL PROTECTED]] > > On Behalf Of Sorte Per > > Sent: Tuesday, February 26, 2002 12:23 PM > > To: [EMAIL PROTECTED] > > Subject: Re: [DOTNET] Multiple instances of the same windows service > > > > > > I want to install (with installUtil) multiple copies of the > > same exe with different ServiceNames that are not hard-coded. > > > > So far I've passed the ServiceName from the installUtil.exe > > via Installer.Context to set the ServiceInstaller.ServiceName. > > > > What I need is to pass the ServiceName to the Main() of my > > service in order to set the ServiceBase.ServiceName. I don't > > think it's possible to specify parameters for the service > > using installUtil.exe, so I probably have to do the registry > > work myself. > > -- > > Per > > > > This e-mail and any attachment is for authorised use by the intended recipient(s) only. It may contain proprietary material, confidential information and/or be subject to legal privilege. It should not be copied, disclosed to, retained or used by, any other party. If you are not an intended recipient then please promptly delete this e-mail and any attachment and all copies and inform the sender. Thank you. > > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or > subscribe to other DevelopMentor lists at http://discuss.develop.com. > You can read messages from the DOTNET archive, unsubscribe from DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.