0

我目前正在开发一个 msi,并且在从 wix 项目启动服务时遇到了一些问题。这是用于复制exe文件(即服务)并安装服务的xml。

    <Component Id='MatcherService' Guid='{81EC2888-DFA6-49BA-829A-5A8354D89310}' Directory='MATCHERDIR'>
          <File Id='MatchingServer.exe' Source='$(var.Matcher.TargetDir)\MatchingServer.exe'/>
          <ServiceInstall
             Id="ServiceInstaller1"
             Type="ownProcess"
             Name="Matcher1"
             DisplayName="Matching Service 1"
             Description="test"
             Start="auto"
             Account="NT AUTHORITY\NETWORK SERVICE"
             Interactive="no"
             ErrorControl="normal"
             Vital="yes">
            <util:PermissionEx
               User="Everyone"
               GenericAll="yes"
               ServiceChangeConfig="yes"
               ServiceEnumerateDependents="yes"
               ChangePermission="yes"
               ServiceInterrogate="yes"
               ServicePauseContinue="yes"
               ServiceQueryConfig="yes"
               ServiceQueryStatus="yes"
               ServiceStart="yes"
               ServiceStop="yes" />
          </ServiceInstall>
 <ServiceControl Id="StartService1" Stop="both" Remove="uninstall" Name="Matcher1" Wait="yes"/>
</Component>

这只会安装服务,当我打开服务时,我可以正常启动该服务。

面临的问题是我想要这个 MatchingServer.exe 的几个实例作为服务运行,我想要 30 个实例。

我试着这样做:

<Component Id='MatcherService' Guid='{81EC2888-DFA6-49BA-829A-5A8354D89310}' Directory='MATCHERDIR'>
      <File Id='MatchingServer.exe' Source='$(var.Matcher.TargetDir)\MatchingServer.exe'/>
      <ServiceInstall
         Id="ServiceInstaller1"
         Type="ownProcess"
         Name="Matcher1"
         DisplayName="Matching Service 1"
         Description="test"
         Start="auto"
         Account="NT AUTHORITY\NETWORK SERVICE"
         Interactive="no"
         ErrorControl="normal"
         Vital="yes">
        <util:PermissionEx
           User="Everyone"
           GenericAll="yes"
           ServiceChangeConfig="yes"
           ServiceEnumerateDependents="yes"
           ChangePermission="yes"
           ServiceInterrogate="yes"
           ServicePauseContinue="yes"
           ServiceQueryConfig="yes"
           ServiceQueryStatus="yes"
           ServiceStart="yes"
           ServiceStop="yes" />
      </ServiceInstall>

      <ServiceInstall
        Id="ServiceInstaller2"
        Type="ownProcess"
        Name="Matcher2"
        DisplayName="Matching Service 2"
        Description="test"
        Start="auto"
        Account="NT AUTHORITY\NETWORK SERVICE"
        Interactive="no"
        ErrorControl="normal"
        Vital="yes">
        <util:PermissionEx
           User="Everyone"
           GenericAll="yes"
           ServiceChangeConfig="yes"
           ServiceEnumerateDependents="yes"
           ChangePermission="yes"
           ServiceInterrogate="yes"
           ServicePauseContinue="yes"
           ServiceQueryConfig="yes"
           ServiceQueryStatus="yes"
           ServiceStart="yes"
           ServiceStop="yes" />
      </ServiceInstall>

      <ServiceControl Id="StartService1" Stop="both" Remove="uninstall" Name="Matcher1" Wait="yes"/>
      <ServiceControl Id="StartService2" Stop="both" Remove="uninstall" Name="Matcher2" Wait="yes"/>
    </Component>

这显然会产生编译错误。我成功地从这样的批处理文件中做到了这一点:

MatchingServer.exe -i 1 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 2 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 3 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 4 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 5 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 6 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 7 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 8 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 9 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 10 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 11 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 12 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 13 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 14 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 15 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 16 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 17 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 18 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 19 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 20 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 21 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 22 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 23 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 24 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 25 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 26 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 27 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 28 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 29 -l "NT AUTHORITY\NETWORKSERVICE"
MatchingServer.exe -i 30 -l "NT AUTHORITY\NETWORKSERVICE"

并进行自定义操作来执行此批处理文件。但我想在wix“内部”执行此操作。

如何在不使用批处理文件的情况下生成同一个 .exe 文件的 30 个服务实例,但名称与 wix 不同?

4

1 回答 1

1

Windows 服务并非旨在执行此操作。如果您需要同一服务器的 30 个实例,则需要在 windows 内创建 30 个独特的服务。

我可能会建议,如果每个服务都是副本,那么您可以通过在您的应用程序中启动多个线程来做到这一点。如果您有静态类,您可能需要对应用程序域做一些花哨的操作,或者您可以生成由主 exe(您的服务)管理的 30 个 exe。

于 2013-05-22T08:57:10.773 回答