如何创建窗口服务的多个实例?多个、实例、窗口

2023-09-04 03:53:48 作者:宁缺爱不滥情

我想不用再安装窗口服务运行在服务器上安装一个窗口服务的多个实例。

I want to run multiple instances of a window service installed on a server without installing window service 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.

我做的是继承安装,这样它创建一个的ServiceInstaller 和 ServiceProcessInstaller ,并给出了一个服务名称(在运行时,通过自定义安装程序)的的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.