与依赖关系安装Windows服务 [英] Installing a Windows Service with dependencies

查看:472
本文介绍了与依赖关系安装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到项目中。
  • 添加一个派生自<一类href="http://msdn.microsoft.com/en-us/library/system.configuration.install.installer.aspx">System.Configuration.Install.Installer和有<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.runinstallerattribute.aspx">RunInstaller属性应用。
  • 在它的构造同时创建<一个href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceprocessinstaller(VS.80).aspx">ServiceProcessInstaller和<一href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller(VS.80).aspx">ServiceInstaller对象。
  • 在您标记所有你想要的依赖关系的ServiceInstaller对象/需要的<一个href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.servicesdependedon(VS.80).aspx">ServicesDependedOn属性。
  • 在加入这两个安装程序的<一个href="http://msdn.microsoft.com/en-us/library/system.configuration.install.installercollection(VS.80).aspx">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服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆