从Wix启动Windows服务的多个实例

时间:2013-05-22 06:16:40

标签: windows-services wix

我目前正在开发一个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“内部”这样做。

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

1 个答案:

答案 0 :(得分:1)

Windows服务不是为此而设计的。如果您需要同一服务器的30个实例,则需要在Windows中创建30个唯一服务。

我可能会建议,如果每个服务都是副本,那么你可以通过在你的应用程序中启动多个线程来实现。如果你有静态课程,你可能需要与app域做一些花哨的步法,或者你可以产生由主exe(你的服务)管理的30个exes。