Write a Windows Service Question 2: Explore the relationship between the service and the installer

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.