Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

.net - Installing a Windows Service with dependencies

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.

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can write a self-installing service and have it set a list of services your service depends on when the installer is executed.

Basic steps:

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);
            }
        }
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...