ServiceInstaller.Install(IDictionary) 方法
定义
通过向注册表写入服务应用程序信息来安装服务。Installs the service by writing service application information to the registry. 该方法旨在由自动处理适当方法的安装工具使用。This method is meant to be used by installation tools, which process the appropriate methods automatically.
public:
override void Install(System::Collections::IDictionary ^ stateSaver);
public override void Install (System.Collections.IDictionary stateSaver);
override this.Install : System.Collections.IDictionary -> unit
Public Overrides Sub Install (stateSaver As IDictionary)
参数
- stateSaver
- IDictionary
IDictionary,包含与安装关联的上下文信息。An IDictionary that contains the context information associated with the installation.
例外
安装不包含可执行文件的 ServiceProcessInstaller。The installation does not contain a ServiceProcessInstaller for the executable.
-或--or-
程序集的文件名为 null 或空字符串。The file name for the assembly is null or an empty string.
-或--or- 服务名无效。The service name is invalid.
-或--or- 未能打开服务控制管理器。The Service Control Manager could not be opened.
服务的显示名称的长度超过 255 个字符。The display name for the service is more than 255 characters in length.
系统未能生成服务的句柄。The system could not generate a handle to the service.
-或--or-
该名称的服务已安装。A service with that name is already installed.
注解
通常情况下,你不会在 ServiceInstaller 你的代码内调用方法; 通常仅由安装实用工具调用这些方法。Normally, you will not call the methods on ServiceInstaller within your code; they are generally called only by the install utility. 安装实用程序会 Install 在安装过程中自动调用此方法。The install utility automatically calls the Install method during installation. 如果需要,它会 Rollback 在生成异常的对象上调用,从而支持故障。It backs out failures, if necessary, by calling Rollback on the object that generated the exception.
应用程序的安装例程会使用项目安装程序的,自动维护有关已安装的组件的信息 Installer.Context 。An application's install routine maintains information automatically about the components that were already installed, using the project installer's Installer.Context. 作为参数传递到的此状态信息 Install stateSaver 会不断更新为 ServiceProcessInstaller 实例,并且每个 ServiceInstaller 实例由实用工具安装。This state information, passed into Install as the stateSaver parameter, is continuously updated as the ServiceProcessInstaller instance and each ServiceInstaller instance is installed by the utility. 通常不需要让代码显式修改此状态信息。It is usually unnecessary for your code to modify this state information explicitly.
ServiceProcessInstaller与项目安装类关联的将安装对项目中的所有实例都通用的信息 ServiceInstaller 。The ServiceProcessInstaller associated with your project installation class installs information common to all ServiceInstaller instances in the project. 如果此服务具有与安装项目中的其他服务分隔的任何内容,则此方法会安装该服务特定的信息。If this service has anything that separates it from the other services in the installation project, that service-specific information is installed by this method.
若要安装服务,请创建一个从类继承的项目安装程序类 Installer ,并将 RunInstallerAttribute 类的特性设置为 true 。To install a service, create a project installer class that inherits from the Installer class, and set the RunInstallerAttribute attribute on the class to true. 在项目中, ServiceProcessInstaller 为每个服务应用程序创建一个实例,并 ServiceInstaller 为应用程序中的每个服务创建一个实例。Within your project, create one ServiceProcessInstaller instance per service application, and one ServiceInstaller instance for each service in the application. 在项目安装程序类构造函数中,使用和实例设置服务的安装 ServiceProcessInstaller 属性 ServiceInstaller ,并将实例添加到集合中 Installers 。Within your project installer class constructor, set the installation properties for the service using the ServiceProcessInstaller and ServiceInstaller instances, and add the instances to the Installers collection.
备注
建议使用构造函数来添加安装程序实例;但是,如果需要 Installers 在方法中将添加到集合中 Install ,请确保在方法中对集合执行相同的添加 Uninstall 。It is recommended that you use the constructor for adding installer instances; however, if you need to add to the Installers collection in the Install method, be sure to perform the same additions to the collection in the Uninstall method.
对于从类派生的所有类 Installer ,集合的状态 Installers 在和方法中必须相同 Install Uninstall 。For all classes deriving from the Installer class, the state of the Installers collection must be the same in the Install and Uninstall methods. 但是, Install Uninstall 如果将安装程序实例添加到 Installers 自定义安装程序类构造函数中的集合,则可以避免在和方法中维护集合。However, you can avoid the maintenance of the collection across the Install and Uninstall methods if you add installer instances to the Installers collection in your custom installer class constructor.