Wix ServiceInstall Arguments

Does anyone know how to get the arguments that I declare in ServiceInstall to pass to the service at startup? They always seem to be null in my OnStart (string [] args).

<ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Name="MyService" DisplayName="MyService" Description="MyService Desc" Start="auto" Account="LocalSystem" ErrorControl="ignore" Interactive="yes" Arguments="MY ARGS HERE" > </ServiceInstall> <ServiceControl Id="ServiceControl" Start="install" Stop="both" Remove="uninstall" Name="MyService" Wait="yes" /> 
+4
source share
2 answers

Kind of old, but here's what you can do

  <ServiceInstall Id="SomeService" Type="ownProcess" Vital="yes" Name="Some Service" DisplayName="Some Service" Description="Monitoring and management of some service" Start="auto" Account="LocalSystem" ErrorControl="normal" Interactive="no"/> <ServiceControl Id="StartSomeService" Start="install" Stop="both" Remove="uninstall" Name="Some Service" Wait="yes"> <ServiceArgument>[P_USEREMAIL]</ServiceArgument> <ServiceArgument>[P_USERPASSWORD]</ServiceArgument> <ServiceArgument>[P_DEFAULTNAMINGCONTEXT]</ServiceArgument> <ServiceArgument>[P_USEHTTPPROXY]</ServiceArgument> <ServiceArgument>[P_PROXYADDRESS]</ServiceArgument> <ServiceArgument>[P_PROXYDOMAIN]</ServiceArgument> <ServiceArgument>[P_PROXYUSERNAME]</ServiceArgument> <ServiceArgument>[P_PROXYPASSWORD]</ServiceArgument> </ServiceControl> 

Update. The WIX documentation is tragically unmanageable when it comes to this element.

Basically, you can set (public) WIX variables defined as [P_ *] for normal (for example, msiexec, static, or CA arguments). These values ​​are passed to the service at startup in the same way as if you combined these values ​​in a string that you send as startup parameters when the service starts from the services console (or with an empty start, which I imagine). In my case, these were values ​​separated by spaces, for example. [P_USERMAIL] - "--useremail some@email.com ", although this is arbitrary, since you will handle this in the startup code of the service you hosted.

As you probably know, these values ​​are not saved. If the service is not initialized with the values ​​specified by you, you must either reinstall / restore, or transfer them to the service in another way (for example, the services console, starting the network).

+3
source

Is anyone making progress on this? I do not see these arguments fall into my service at startup:

  <ServiceInstall Id="ServiceInstaller" Type="ownProcess" Vital="yes" Name="Service" DisplayName="Service" Description="a service" Arguments="-p stuff" Start="auto" Account="LocalSystem" ErrorControl="normal" Interactive="yes"/> 

my service always gets an empty arg array:

  partial class PrintMonitorService : ServiceBase { private readonly PrintMonitorServiceManager _serviceManager; public PrintMonitorService() { InitializeComponent(); _serviceManager = new PrintMonitorServiceManager(); } protected override void OnStart(string[] args) { _serviceManager.StartHosting(args); } protected override void OnStop() { _serviceManager.StopHosting(); } 
+2
source

Source: https://habr.com/ru/post/1412804/


All Articles