本文介绍了与依赖关系安装Windows服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的安装程序不suppport安装服务,但我可以运行等等,所以我的问题是我怎么能安装一个Windows服务并使用命令行中添加2依赖程序/命令行?该计划是一个.NET 2.0应用程序。
My installer program doesn't suppport installing services but I can run a program/command line etc so my question is how can I install a Windows Service and add 2 dependencies using the command line? The program is a .Net 2.0 app.
感谢
推荐答案
您可以编写一个自安装服务,并有它设置服务的列表中选择您的服务取决于执行安装程序时上。
You can write a self-installing service and have it set a list of services your service depends on when the installer is executed.
基本步骤:
- 添加引用System.Configuration.Install到项目中。
- 添加一个派生自System.Configuration.Install.Installer和有RunInstaller属性应用。
- 在它的构造同时创建ServiceProcessInstaller和ServiceInstaller对象。
- 在您标记所有你想要的依赖关系的ServiceInstaller对象/需要的ServicesDependedOn属性。
- 在加入这两个安装程序的InstallersCollection安装人员从System.Configuration.Install.Installer继承
- 完成的。
- Add a reference to System.Configuration.Install to your project.
- Add a class that derives from System.Configuration.Install.Installer and has the RunInstaller attribute applied.
- In its constructor create both a ServiceProcessInstaller and a ServiceInstaller object.
- On the ServiceInstaller object you mark all the dependencies you want/need with the ServicesDependedOn property.
- Add these two installers to the InstallersCollection your installer inherited from System.Configuration.Install.Installer
- done.
编辑:忘了提,你可以使用例如 Installutil.exe 以调用安装程序。
edit: forgot to mention that you can use e.g. Installutil.exe to invoke the installer.
[RunInstaller(true)]
public class MyServiceInstaller : Installer
{
public MyServiceInstaller()
{
using ( ServiceProcessInstaller procInstaller=new ServiceProcessInstaller() ) {
procInstaller.Account = ServiceAccount.LocalSystem;
using ( ServiceInstaller installer=new ServiceInstaller() ) {
installer.StartType = ServiceStartMode.Automatic;
installer.ServiceName = "FooService";
installer.DisplayName = "serves a lot of foo.";
installer.ServicesDependedOn = new string [] { "CLIPBOOK" };
this.Installers.Add(procInstaller);
this.Installers.Add(installer);
}
}
}
}
这篇关于与依赖关系安装Windows服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!