有谁知道如何获取我在ServiceInstall中声明的参数在启动时传递给服务?它们在我的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" />
Run Code Online (Sandbox Code Playgroud)
有点旧,但这是你能做的
<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>
Run Code Online (Sandbox Code Playgroud)
更新:当涉及到这个元素时,WIX文档是悲惨的.
基本上,您可以设置(公共)WIX变量,通常定义为[P_*](例如msiexec参数,静态或CA).这些值在启动时传递给服务的方式与在服务控制台启动服务时(或者我想象的net start)作为启动参数提供的字符串中连接这些值的方式相同.在我的例子中,这些是空格分隔的值,例如[P_USERMAIL]是"--useremail some@email.com",虽然这是任意的,因为您将在您发布的服务启动代码中处理此问题.
您可能知道,这些值不会持久存在.如果服务无法使用您提供的值进行初始化,则需要重新安装/修复或以其他方式将其传递给服务(即服务控制台,net start).
有人在这方面取得进展吗?我没有看到这个参数在启动时影响我的服务:
<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"/>
Run Code Online (Sandbox Code Playgroud)
我的服务总是得到一个空的 arg 数组:
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();
}
Run Code Online (Sandbox Code Playgroud)