C# 使用启动参数安装Windows服务
我正在尝试使用批处理文件的启动参数安装windows服务 我有一个服务名,它被传递到安装程序中以获取实例名。我还想设置服务启动参数。通过将arg传递给安装程序,我没有问题。我在启动参数设置时出错 代码段:C# 使用启动参数安装Windows服务,c#,.net,batch-file,windows-services,C#,.net,Batch File,Windows Services,我正在尝试使用批处理文件的启动参数安装windows服务 我有一个服务名,它被传递到安装程序中以获取实例名。我还想设置服务启动参数。通过将arg传递给安装程序,我没有问题。我在启动参数设置时出错 代码段: set serviceName=FSER C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /servicename="%serviceName%" "%UserProfile%\AppData\Loc
set serviceName=FSER
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe /servicename="%serviceName%" "%UserProfile%\AppData\Local\SERVER\%serviceName%\tser.exe "%serviceName%" " /logfile=install.log
引用语的使用有问题吗?尝试用反斜杠转义内部引号,如
"\"myExeFile.exe\" \"myParameter\""
我不太了解InstallUtil,但它失败了,需要InstallUtil,使用InstallUtil安装服务,但不带参数,然后使用sc.exe重新配置服务,包括binPath中的参数。我通过在服务安装程序“Assemblypath”中添加参数解决了问题: 此方法会留下一些丑陋的“.For me Context.Parameters[“assemblypath”]=string.Format(“\”{0}\“/i1/d23”,Context.Parameters[“assemblypath”]);按预期工作。原始的assemblypath将被“而参数保持不变”包围
protected override void OnBeforeInstall(IDictionary savedState)
{
string parameter = "YOUR COMMAND LINE PARAMETER VALUE GOES HERE";
var assemblyPath = Context.Parameters["assemblypath"];
assemblyPath += @""" "" " + parameter + "";
Context.Parameters["assemblypath"] = assemblyPath;
base.OnBeforeInstall(savedState);
}