Note: There is a Document sub folder and an InstallerBatch sub folder included in the entire solution containing some good information/comments and the installation/uninstallation batch files.
What I am Trying to Achieve
I'm trying to put multiple services into one service, with one same name. So, When you do "net start TheService", it will start
Service1()
and
MySecondUserService()
.
What I Have Done
I thought adding another service to my project and changing the services to run would be sufficient.
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[] {new Service1(), new MySecondUserService()};
ServiceBase.Run(ServicesToRun);
When I install and run this,
only the first service is run "Service1".
The solutions is not to add another project installer, but a service installer, which is a component on the project installer. That newly added service installer has to have second service name configured.
Another
example?
href="http://stackoverflow.com/questions/2820216/multiple-windows-services-in-a-single-project-mystery">http://stackoverflow.com/questions/2820216/multiple-windows-services-in-a-single-project-mystery
Like code below:
Installer1.cs[Design]
Must have 2 serviceInstaller
’s and 1 serviceProcessInstaller
In Installer1.Designer.cs code must be like below:
#region Component Designer generated code
private void InitializeComponent()
{
this.serviceProcessInstaller1 = new System.ServiceProcess.ServiceProcessInstaller();
this.serviceInstaller1 = new System.ServiceProcess.ServiceInstaller();
this.serviceInstaller3 = new System.ServiceProcess.ServiceInstaller();
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
this.serviceInstaller1.Description = "TEST WATCHER1";
this.serviceInstaller1.DisplayName = "Test Watcher1";
this.serviceInstaller1.ServiceName = "Test Watcher Service #1";
this.serviceInstaller3.Description = "TEST WATCHER3";
this.serviceInstaller3.DisplayName = "Test Watcher3";
this.serviceInstaller3.ServiceName = "Test Watcher Service #3";
this.Installers.AddRange(new System.Configuration.Install.Installer[] {
this.serviceProcessInstaller1,
this.serviceInstaller1,
this.serviceInstaller3});
}
#endregion
private System.ServiceProcess.ServiceProcessInstaller serviceProcessInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;
private System.ServiceProcess.ServiceInstaller serviceInstaller3;
In both Service1.Designer.cs and Service3.Designer.cs files, below must be true:
this.ServiceName MUST match this.serviceInstaller1.ServiceName in Installer1.Designer.cs file
this.ServiceName MUST match this.serviceInstaller3.ServiceName in Installer1.Designer.cs file
ADVANTAGE
- Putting multiple services in one single Windows Service
.exe file can allow one step installation. One installation will have all the
services installed in the Service Controller and all can be viewed in the
Services MMC snap-in. - Also may be multiple services can share code.
ISSUE
The only issue found so far is that after all the services started, if one or more (but not all) stopped, the "stopped" service(s) is/are still running somehow at the background. To avoid this type of behavior, all other services that still need to run will have to do a restart in order to have all the stopped services truly stop.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.