ServiceProcessInstaller 类
安装一个可执行文件,该文件包含扩展 ServiceBase的类。该类由安装实用工具(如 InstallUtil.exe)在安装服务应用程序时调用。
命名空间:System.ServiceProcess
程序集:System.ServiceProcess(在 system.serviceprocess.dll 中)
public class ServiceProcessInstaller : ComponentInstaller
public class ServiceProcessInstaller extends ComponentInstaller
ServiceProcessInstaller 执行可执行文件中的所有服务的公共操作。安装实用工具使用它来写与要安装服务关联的注册表值。
若要安装服务,请创建一个从 Installer 继承的项目安装程序类,然后将该类上的 RunInstallerAttribute 设置为 true。在项目中,为每个服务应用程序实例化一个 ServiceProcessInstaller 实例,并为应用程序中的每个服务实例化一个 ServiceInstaller 实例。最后,向项目安装程序类添加 ServiceProcessInstaller 实例和 ServiceInstaller 实例。
当 InstallUtil.exe 运行时,该实用工具在服务程序集内查找 RunInstallerAttribute 设置为 true 的类。通过将类添加到与项目安装程序关联的 Installers 集合来向服务程序集添加类。如果 RunInstallerAttribute 为 false,安装实用工具将忽略项目安装程序。
对于 ServiceProcessInstaller 实例,可修改的属性包括指定服务应用程序在登录用户之外的帐户下运行。可指定运行该服务所使用的特定 Username 和 Password 对,或者可使用 Account 指定该服务是在计算机的系统帐户、本地或网络服务帐户还是用户帐户下运行。
注意 |
---|
计算机的“系统”帐户与“管理员”帐户不同。 |
通常,不在自己的代码中调用 ServiceInstaller 上的方法,这些方法通常只由安装实用工具来调用。在安装进程中,安装实用工具自动调用 ServiceProcessInstaller.Install 和 ServiceInstaller.Install 方法。必要时,它退出故障,方法是在以前安装的所有组件上调用 Rollback(或 ServiceInstaller.Rollback)。
使用项目安装程序的 Installer.Context,应用程序的安装例程自动维护有关已安装组件的信息。该状态信息作为 ServiceProcessInstaller 实例而持续更新,并且每个 ServiceInstaller 实例均由实用工具来安装。通常,不必通过代码显式修改此状态信息。
实例化 ServiceProcessInstaller 将导致调用基类构造函数 ComponentInstaller。
下面的示例创建一个名为 MyProjectInstaller 的项目安装程序,它从 Installer 继承。假定有一个服务可执行文件,它包含“Hello-World Service 1”和“Hello-World Service 2”两个服务。在 MyProjectInstaller 的构造函数(它由安装实用工具调用)内,为每个服务创建若干 ServiceInstaller 对象,并为可执行文件创建一个 ServiceProcessInstaller。为使安装实用工具将 MyProjectInstaller 识别为有效安装程序,RunInstallerAttribute 属性被设置为 true。
首先在进程安装程序和服务安装程序上设置可选属性,然后向 Installers 集合添加这些安装程序。当安装实用工具访问 MyProjectInstaller 时,将依次安装通过调用 InstallerCollection.Add 添加到 Installers 集合的对象。在该过程中,安装程序维护状态信息,这些信息指示哪些对象已安装,以便在安装失败时可依次退出各个对象。
通常,不显式实例化项目的安装程序类。您可以创建该类并添加 RunInstallerAttribute,但实际上是由安装实用工具来调用该类并初始化它。
using System; using System.Collections; using System.Configuration.Install; using System.ServiceProcess; using System.ComponentModel;[RunInstallerAttribute(true)] public class MyProjectInstaller: Installer{private ServiceInstaller serviceInstaller1;private ServiceInstaller serviceInstaller2;private ServiceProcessInstaller processInstaller;public MyProjectInstaller(){// Instantiate installers for process and services.processInstaller = new ServiceProcessInstaller();serviceInstaller1 = new ServiceInstaller();serviceInstaller2 = new ServiceInstaller();// The services run under the system account.processInstaller.Account = ServiceAccount.LocalSystem;// The services are started manually.serviceInstaller1.StartType = ServiceStartMode.Manual;serviceInstaller2.StartType = ServiceStartMode.Manual;// ServiceName must equal those on ServiceBase derived classes. serviceInstaller1.ServiceName = "Hello-World Service 1";serviceInstaller2.ServiceName = "Hello-World Service 2";// Add installers to collection. Order is not important.Installers.Add(serviceInstaller1);Installers.Add(serviceInstaller2);Installers.Add(processInstaller);} }
ServiceProcessInstaller 类相关推荐
- 用C#创建Windows服务(Windows Services)
转载自 hyslove 最终编辑 hyslove Windows服务在Visual Studio 以前的版本中叫NT服务,在VS.net启用了新的名称.用Visual C# 创建Windows服务不是 ...
- 接Window服务(二)
接Window服务(一) ServiceController方法调用 1 public partial class Service1 : ServiceBase 2 { 3 public Servic ...
- window 服务(二)
window 服务(二) 接Window服务(一) ServiceController方法调用 public partial class Service1 : ServiceBase { public ...
- *用C#创建Windows服务(Windows Services)
Windows服务在Visual Studio 以前的版本中叫NT服务,在VS.net启用了新的名称.用Visual C# 创建Windows服务不是一件困难的事,本文就将指导你一步一步创建一个Win ...
- 没有RunInstallerAttribute.Yes的公共安装程序。
1.在视图状态 右键添加ServiceInstaller及ServiceProcessInstaller两个控件; 2.将serviceProcessInstaller类的Account属性改为 Lo ...
- WindowsService服务程序开发
转自:http://www.cnblogs.com/babycool/p/3534786.html Windows服务:Microsoft Windows 服务(即,以前的 NT服务)使您能够创建在它 ...
- .NET Windows服务应用程序
此文旨在记录个人对windows服务的理解以及学习记录,高人可以直接绕行. 1.Windows 服务体系结构 @http://technet.microsoft.com/zh-cn/library/a ...
- C# windows服务:创建Windows服务(Windows Services)的一般步骤
C#创建Windows服务(Windows Services) Windows服务在Visual Studio 以前的版本中叫NT服务,在VS.net启用了新的名称.用Visual C# 创建Wind ...
- c#中regex的命名空间_c#命名空间
System.Transactions 命名空间 注意:此命名空间在 .NET Framework 2.0 版中是新增的. 使用 System.Transactions 命名空间包含的类可以编写自己的 ...
最新文章
- 肠·道 | 朱元方:产检消毒恐误伤菌脉,6大举措则促菌脉相承
- hdu Turn the corner
- pythond的执行原理_D*路径规划算法及python实现
- 让8只数码管从左往右显示1、2、3、4、、、8
- 构造器2(Java)
- 无问西东,哪怕重头来过
- 计算机系统分析师高级试题及答案,2013年计算机软考系统分析师试题及答案1
- 六、鼎捷T100生产管理之生产入库管理篇
- Sqlmap常用命令总结及注入实战(Access、mysql)
- 幽灵蛛(pholcus)规则(二)
- Php开发Dlp加密,DLP与文档透明加密 后防泄露时代之争
- 北京的三甲医院都是定点医院吗?不列入医保卡范围不能报销?
- 全球四大国际反垃圾邮件组织介绍
- 5G/NR LTE: 物理层抽象 PHY abstraction - SLS LLS 系统级仿真和链路级仿真
- 通信工程毕业设计 - 选题推荐
- Some weights of the model checkpoint at bert_pretrain were not used when initializing BertModel
- Mac苹果电脑思维导图Xmind 2022中文
- 关于导出文件中文名乱码问题,response.setHeader(),postman测试有误,直接用浏览器测试
- 最后几张票,送完即止:KubeCon 2021中国大会
- 华云数据董事长许广彬接受中央电视台采访:推动职业教育发展