简体   繁体   中英

What launches the installation of a Windows Service Installer?

I have created a Service using Microsoft's walkthrough .

It works. But I don't understand how. The Main() method doesn't seem to call the ProjectInstaller constructor (which looks like what installs the service). In fact, ProjectInstaller isn't referenced anywhere in the solution (I checked using Shift + F12 ).

So how is it executed?

EDIT

I'm not using installutil . Program 's Main() calls ManagedInstallerClass.InstallHelper(args); .

Program which you use to install that service ( installutil.exe ) inspects your assembly and runs installers. As stated in its documentation :

Installutil.exe uses reflection to inspect the specified assemblies and to find all Installer types that have the System.ComponentModel.RunInstallerAttribute attribute set to true.

The tool then executes either the Installer.Install or the Installer.Uninstall method on each instance of the Installer type. Installutil.exe performs installation in a transactional manner; that is, if one of the assemblies fails to install, it rolls back the installations of all other assemblies. Uninstall is not transactional.

Update: You said you do not use installutil and instead using ManagedInstallerClass.InstallHelper . Reading documentation of this class:

This API supports the product infrastructure and is not intended to be used directly from your code.

Handles the functionality of the Installutil.exe (Installer Tool).

So first you should not be using it, and second - it does the same as installutil (so related to this question - uses reflection to inspect your assembly and run installers). I suppose that installutil tool actually just calls this method. Note that you have to pass path to your assembly in args of ManagedInstallerClass.InstallHelper , that's how it knows which assembly to inspect with reflection and run installer for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM