Reputation: 8981
I'm currently working on a msi, and am facing some problems with starting services from the wix project. This is the xml for copying the exe file, which is the service, and installing the service.
<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>
This only installs the Service, and when I open Services, I'm able to start this service properly.
The problem am facing is that I want several instance of this MatchingServer.exe to run as a service, I want 30 instances.
I tried to do it this way:
<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>
This will obviously give compile errors. I succeeded doing this from a batch file like this:
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"
And making a custom action to exeute this batch file. But I want to do this "inside" the wix.
How can I spawn 30 service instances of the same .exe file, with different names from wix, without going the way around batch file?
Upvotes: 0
Views: 167
Reputation: 29332
Windows services aren't designed to do this. If you need 30 instances of the same server, you need to create 30 unique services inside windows.
I might recommend though that if each service is a copy then you could do this by launching multiple threads, within your app. If you have static classes, you might need to do some fancy footwork with app domains OR you could spawn 30 exes managed by a master exe (your service).
Upvotes: 1