windows - 在服务器上安装同一 Windows 服务的多个实例

标签 windows windows-services windows-installer installutil

因此,我们已经制作了一个 Windows 服务来向我们的客户端应用程序提供数据,并且一切顺利。客户提出了一个有趣的配置请求,要求此服务的两个实例在同一台服务器上运行并配置为指向不同的数据库。

到目前为止,我还没有能够做到这一点,希望我的 stackoverflow 成员能够就原因给出一些提示。

当前设置:

我已经设置了包含 Windows 服务的项目,从现在开始我们将其称为 AppService,以及处理自定义安装步骤的 ProjectInstaller.cs 文件,以根据应用程序中的 key 设置服务名称。像这样配置:

this.serviceInstaller1.ServiceName = Util.ServiceName;
this.serviceInstaller1.DisplayName = Util.ServiceName;
this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;

在这种情况下,Util 只是一个从配置文件加载服务名称的静态类。

从现在开始,我尝试了两种不同的方法来安装这两种服务,但均以相同的方式失败。

第一种方式是简单安装服务的第一个副本,复制安装目录并重命名,然后在修改应用程序配置后运行以下命令更改所需的服务名称:

InstallUtil.exe /i AppService.exe

当这不起作用时,我尝试创建第二个安装程序项目,编辑配置文件并构建第二个安装程序。当我运行安装程序时,它工作正常,但服务没有出现在 services.msc 中,所以我对第二个安装的代码库运行了上一个命令。

我两次从 InstallUtil 收到以下输出(仅相关部分):

Running a transacted installation.

Beginning the Install phase of the installation.

Installing service App Service Two... Service App Service Two has been successfully installed. Creating EventLog source App Service Two in log Application...

An exception occurred during the Install phase. System.NullReferenceException: Object reference not set to an instance of an object.

The Rollback phase of the installation is beginning.

Restoring event log to previous state for source App Service Two. Service App Service Two is being removed from the system... Service App Service Two was successfully removed from the system.

The Rollback phase completed successfully.

The transacted install has completed. The installation failed, and the rollback has been performed.

很抱歉这篇冗长的帖子,想确保有足够的相关信息。到目前为止让我感到困惑的是它声明服务的安装已成功完成,并且只有在它去创建 NullReferenceException 似乎被抛出的 EventLog 源之后。因此,如果有人知道我做错了什么或有更好的方法,我们将不胜感激。

最佳答案

您是否尝试过 sc/service controller 实用程序?类型

sc create

在命令行中,它会为您提供帮助条目。我想我过去曾为 Subversion 做过这件事并使用过 this article作为引用:

http://svn.apache.org/repos/asf/subversion/trunk/notes/windows-service.txt

关于windows - 在服务器上安装同一 Windows 服务的多个实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1279383/

相关文章:

windows - 设置 (Windows) Hadoop 集群

wix - Wix 中的 InstallScope ="perMachine"没有区别

windows - 如何正确配置与 Windows Azure Server 的 FTP 连接。

c++ - 在 64 位 Windows 上 long 的位大小是多少?

c# - 关于最空闲的 Windows 服务的问题

windows-services - 安装自定义Windows服务时出现错误1001

wix - 为什么我的 MSI 提示需要管理员权限?

installation - 安装签名的 msi 安装程序时出现奇怪的 'Program name'

windows - 将 cordova 应用程序部署到真正的 Windows Phone 8.1 设备时出现问题

.net - 使用 Windows 服务运行 UI