C# 使用InstallUtil在其自己的进程中安装服务

C# 使用InstallUtil在其自己的进程中安装服务,c#,.net,service,installation,C#,.net,Service,Installation,我已使用InstallUtil成功安装了我的服务,但我希望我的服务在自己的进程中运行,而不是在svchost中运行。如果我是通过winmgmts这样做的,我可以将自己的_进程传递给它()。如何使用System.Configuration.Install.Installer执行此操作 我当前的代码: [RunInstaller(true)] public partial class MyServiceInstaller : Installer { private Service

我已使用InstallUtil成功安装了我的服务,但我希望我的服务在自己的进程中运行,而不是在svchost中运行。如果我是通过winmgmts这样做的,我可以将自己的_进程传递给它()。如何使用System.Configuration.Install.Installer执行此操作

我当前的代码:

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

不是所有Windows服务都必须在SVC主机内运行吗

当您安装服务时,它只是服务的一个注册表项,当windows启动时,它会扫描这些条目并在服务主机内加载所需的进程。然后,它们监控服务,并提供诸如auto之类的设施。重新启动tc


如果您希望您的服务作为普通exe运行,那么我理解您失去了windows服务模型提供的功能。

我将不得不假设,使用此方法不可能做到这一点。很久以前,我只是使用另一种方法(sc.exe)来实现这一点。

否。并非所有服务都必须在svchost中运行。我只是使用sc.exe来完成。请注意type=own参数,“服务在其自己的进程中运行。它不与其他服务共享可执行文件。这是默认值。”