First of all, to get two services, one called "Airplane", one called "Train".
Public class Feijiservice:servicebase { public feijiservice () { "fei_ji"; } } Publicclass huocheservice:servicebase { public Huocheservice () { "huo_che"; } }
For demonstration, the service is very single, next, match the installer.
[Runinstaller (true)] Public classSelfinstaller:installer { PublicSelfinstaller () {ServiceInstaller Fjinstaller=NewServiceInstaller (); Fjinstaller. ServiceName="Fei_ji"; Fjinstaller. Description="domestic aircraft--008"; Fjinstaller. DisplayName="Aircraft"; Installers.add (Fjinstaller); ServiceProcessInstaller Processinstaller=NewServiceProcessInstaller (); Processinstaller. Account=Serviceaccount.localsystem; Installers.add (Processinstaller); } }
Here I have a ghost, only installed the "aircraft" service, "train" service is not installed.
Finally, you run two services at the main entry point.
Static void Main () { = { new feijiservice (), new Huocheservice () }; Servicebase.run (SVS); }
Let's just check to see if the service that is not installed is going to work.
Now, execute InstallUtil xxx.exe to install, after installation, in Service Manager only see "Airplane", do not see "train".
Obviously, only the "aircraft" service can be started at this time, and the "train" service is not in the list of services.
It appears that only post-installation services can be started.
Next, modify the installer code again to install the "train" service.
PublicSelfinstaller () {ServiceInstaller Fjinstaller=NewServiceInstaller (); Fjinstaller. ServiceName="Fei_ji"; Fjinstaller. Description="domestic aircraft--008"; Fjinstaller. DisplayName="Aircraft"; Installers.add (Fjinstaller); ServiceInstaller Hcinstaller=NewServiceInstaller (); Hcinstaller. ServiceName="Huo_che"; Hcinstaller. Description="Domestic trains"; Hcinstaller. DisplayName="Train"; Installers.add (Hcinstaller); ServiceProcessInstaller Processinstaller=NewServiceProcessInstaller (); Processinstaller. Account=Serviceaccount.localsystem; Installers.add (Processinstaller); }
Then, uninstall the service you just installed and execute installutil/u xxx.exe.
Then you build the project again, install it, and then you see two services in Service Manager.
This simple experiment verifies again that a service installer can only be used to install a service, and a service must be installed before it can be started .
Sample code
Write a Windows Service Question 2: Explore the relationship between the service and the installer