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

时间:2011-12-02 12:21:08

标签: c# .net service install

我已经使用InstallUtil成功安装了我的服务,但我希望我的服务能够在自己的进程中运行而不是在svchost中运行。如果我通过说winmgmts这样做,我可以将OWN_PROCESS传递给它(see here)。如何使用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);
    }
  }

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:-1)

不是所有Windows服务都必须在svchost中运行吗?

当您安装服务时,它只是服务的注册表项,当Windows启动时,它会扫描这些条目并在服务主机内加载所需的进程。然后这些监控服务并提供汽车等设施。 restarte tc。

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