如何创建Windows服务的多个实例? [英] How to create multiple instance of Windows Service?

查看:147
本文介绍了如何创建Windows服务的多个实例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想运行服务器上安装的Windows Service的多个实例,而无需再次安装。

I want to run multiple instances of a Windows Service installed on a server without installing it again.

这怎么可能?

推荐答案

服务安装实际上只是在名称,可执行文件和其他一些元数据之间添加映射。安装后,一项服务正在运行(一次)或没有运行。要使多个实例作为服务运行,它们必须使用不同的名称注册,这基本上意味着要多次安装。但这不是 ,这意味着您需要可执行文件的多个不同副本。

A service "installation" is really just adding a mapping between a name, an executable, and a few other bits of metadata. A service, once installed, is either running (once), or it isn't. To have multiple instances running as services, they would have to be registered with different names, which basically means installing it multiple times. That does not, however, mean that you need multiple different copies of the executable.

我这样做的方法是将<$ c子类化$ c>安装程序,以便创建 ServiceInstaller ServiceProcessInstaller ,并给出 ServiceName (在运行时,通过自定义安装程序)到 ServiceInstaller 实例,然后使用 ManagedInstallerClass 在运行时-基本上使独立的exe能够使用命令行参数指定名称来作为服务安装和卸载自身(次数不限)。

The way I do it is to subclass Installer such that it creates a ServiceInstaller and ServiceProcessInstaller, and gives a ServiceName (at runtime, via the custom installer) to the ServiceInstaller instance, then use ManagedInstallerClass at runtime - basically making a standalone exe capable of installing and uninstalling itself as a service (as many times as you like), using command-line parameters to specify the name.

这篇关于如何创建Windows服务的多个实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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