简体   繁体   English

使用InstallUtil自行安装服务

[英]Using InstallUtil to install service in its own process

I have succesfully installed my service using InstallUtil, but I would like my service to run in its own process instead of in svchost. 我已经使用InstallUtil成功安装了我的服务,但是我希望我的服务在其自己的进程中而不是在svchost中运行。 If I was doing this via say winmgmts, I could just pass OWN_PROCESS to it ( see here ). 如果我通过说winmgmts来执行此操作,则可以将OWN_PROCESS传递给它( 请参见此处 )。 How can I do this using a System.Configuration.Install.Installer? 如何使用System.Configuration.Install.Installer执行此操作?

My current code: 我当前的代码:

  [RunInstaller(true)]
  public partial class MyServiceInstaller : Installer
  {
    private ServiceInstaller serviceInstaller;
    private ServiceProcessInstaller processInstaller;

    public MyServiceInstaller ()
    {
      InitializeComponent();

      processInstaller = new ServiceProcessInstaller();
      serviceInstaller = new ServiceInstaller();

      processInstaller.Account = ServiceAccount.LocalSystem;

      serviceInstaller.StartType = ServiceStartMode.Manual;
      serviceInstaller.ServiceName = "MyService";

      Installers.Add(serviceInstaller);
      Installers.Add(processInstaller);
    }
  }

I am going to have to assume that this is not possible with this method. 我将不得不假设这种方法是不可能的。 I long ago simply used another method (sc.exe) to accomplish this. 我很久以前只是使用另一种方法(sc.exe)来完成此操作。

Don't all Windows services have to run inside an svchost? 并非所有Windows服务都必须在svchost中运行吗?

When you install your service its just a registry key to the service, when windows starts up it scans these entries and loads the required processes inside service hosts. 当您安装服务时,它只是服务的注册表项,当Windows启动时,它将扫描这些条目并在服务主机中加载所需的进程。 these then monitor the service and provide the facilities such as auto. 然后,它们监视服务并提供诸如汽车之类的设施。 restarte tc. 重新启动TC。

If you want your service to run as a normal exe then I understand you loose the facilities offered by the windows service model. 如果您希望您的服务以正常exe的形式运行,那么我了解您会松开Windows服务模型提供的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM