简体   繁体   English

使用 Inno Setup 安装具有不同配置的同一 Windows 服务的多个实例

[英]Installing multiple instances of the same Windows service with different configuration using Inno Setup

I'm very new at programming and coding and I've been asked to install a service multiple times and for them to have different config files.我在编程和编码方面很新,我被要求多次安装服务并让他们拥有不同的配置文件。 Here's the thing:事情是这样的:

  • I need to install the same service twice with different names我需要使用不同的名称安装相同的服务两次
  • Each service has to read a different config file每个服务必须读取不同的配置文件

On the config files I have connection settings that need to be different for both services.在配置文件中,我有两个服务的连接设置需要不同。 The service just retrieves information from another controller, but they need to recieve information from two different controllers and that's why they have asked to have two different instances of the same service with different config files.该服务只是从另一个控制器检索信息,但他们需要从两个不同的控制器接收信息,这就是为什么他们要求拥有具有不同配置文件的同一服务的两个不同实例。

I'm stucked with this.我被这个困住了。 I know that both of the services have to have different names.我知道这两个服务必须有不同的名称。 But how can I install them with Inno setup and have them read two different config files?但是如何使用 Inno setup 安装它们并让它们读取两个不同的配置文件?

The service was made with #C, .NET Framework 4.5.2该服务是用 #C、.NET Framework 4.5.2 制作的

I have the simple installer for 1 instance:我有 1 个实例的简单安装程序:

[Files]
Source: "C:\...\Service.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:\...\log4net.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "C:...\Service.exe.config"; DestDir: "{app}"; Flags: ignoreversion

[Run]
Filename: {sys}\sc.exe; \
    Parameters: "create Service start= auto binPath= ""{app}\Service.exe"""; \
    Flags: runhidden

[UninstallRun]
Filename: {sys}\sc.exe; Parameters: "stop Service"; Flags: runhidden
Filename: {sys}\sc.exe; Parameters: "delete Service"; Flags: runhidden

It's a very simple service.这是一项非常简单的服务。 I know how to add Components with checkboxes to make the user choose how many instances they want.我知道如何添加带有复选框的Components ,让用户选择他们想要的实例数量。 But I don't know how to add a second instance and how make the second instance read the second config file.但我不知道如何添加第二个实例以及如何让第二个实例读取第二个配置文件。 Is there something that I need to change in my service code?我的服务代码中有什么需要更改的吗? Is this at all possible?这是可能吗?

I'm sorry for my poor english and if I coudn't explain myself better.我很抱歉我的英语不好,如果我不能更好地解释自己。 I know pretty much nothing about coding and services.我对编码和服务几乎一无所知。 Thanks for your help!谢谢你的帮助!

The name of the service is the first argument after create command.服务名称是create命令后的第一个参数。

So create two entries in the [Run] section, one for each service:因此,在[Run]部分创建两个条目,每个服务一个:

[Run]
Filename: {sys}\sc.exe; \
    Parameters: "create Service1 start= auto binPath= ""{app}\Service.exe""" ; \
    Flags: runhidden
Filename: {sys}\sc.exe; \
    Parameters: "create Service2 start= auto binPath= ""{app}\Service.exe""" ; \
    Flags: runhidden

And similarly for the [UninstallRun] .[UninstallRun]类似。


Regarding the loading of configuration file.关于加载配置文件。 You didn't tell us anything about, how your service code determines where to load the configuration file from in the first place.您没有告诉我们任何有关您的服务代码如何首先确定从何处加载配置文件的信息。

Assuming the path is somehow hardcoded (or somehow programmatically resolved), you can change the code to incorporate the service name into the path.假设路径以某种方式硬编码(或以某种方式以编程方式解析),您可以更改代码以将服务名称合并到路径中。

To determine name of the service instance for which your C# code is currently running, see How can a Windows Service determine its ServiceName?要确定您的 C# 代码当前正在运行的服务实例的名称,请参阅Windows 服务如何确定其 ServiceName?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM