binPath with just one argument
jrgcubano opened this issue · 1 comments
jrgcubano commented
Hi there,
How I can get working somethinkg like this: Just using the BIZ argument.
Directly from PowerShell:
& "sc.exe" create "myservice" binPath= '\"C:/dev/service.exe\" \"BIZ\"' DisplayName= "myservice" start= "auto"
And you get
"C:/dev/service.exe" "BIZ"
Steps
I am trying with something like this... but not working
InstallService(new InstallSettings()
{
ServiceName = "myservice",
DisplayName = "myservice",
Description = "myservice",
ExecutablePath = @"C:/dev/service.exe",
StartMode = "auto",
}.WithArguments(args => args.Append("BIZ")));
Executing: & "sc.exe" create "myservice" binPath= "\"C:/dev/service.exe\" BIZ" DisplayName= "myservice" start= "auto"
With AppendQuoted
InstallService(new InstallSettings()
{
ServiceName = "myservice",
DisplayName = "myservice",
Description = "myservice",
ExecutablePath = @"C:/dev/service.exe",
StartMode = "auto",
}.WithArguments(args => args.AppendQuoted("BIZ")));
Executing: & "sc.exe" create "myservice" binPath= "\"C:/dev/service.exe\" \"BIZ\"" DisplayName= "myservice" start= "auto"
Some posible fix to escape binPath using single quotes
ServiceManager.cs (line 960)
Change:
args.AppendSwitch("binPath=", " ", @"""\""" + settings.ExecutablePath.FullPath + @"\"" " + pathArgs.Replace("\"", "\\\"") + "\"");
By binPath= " .... " -> ' .... ':
args.AppendSwitch("binPath=", " ", "'" + @"\""" + settings.ExecutablePath.FullPath + @"\"" " + pathArgs.Replace("\"", "\\\"") + "'");
Working example using Cake.PowerShell:
Task("Install-Commands-Service")
.WithCriteria(() => parameters.UseCommands)
.Does(() =>
{
if(IsServiceInstalled(commandsSvc))
return;
var exeFilePath = MakeAbsolute((FilePath)($"./{uniNodeCommands}/{uniNodeCommands}.exe")).FullPath;
var installSettings = new InstallSettings
{
ServiceName = commandsSvc,
DisplayName = $"PMS Commands Service {parameters.BizName}",
Description = $"PMS Commands Service {parameters.BizName}",
ExecutablePath = exeFilePath,
StartMode = "auto",
//Username = parameters.Username,
//Password = parameters.Password
}.WithArguments(args =>
args.AppendQuoted($"{parameters.Config}")
);
// InstallService(installSettings);
// Fix until install service fixed
var pathArgs = installSettings.Arguments.Render();
var createSettings = new PowershellSettings
{
FormatOutput = true,
LogOutput = true,
OutputToAppConsole = true,
WorkingDirectory = "./"
}.WithArguments(args =>
{
args
.AppendQuoted(installSettings.ServiceName)
.AppendSwitch("binPath=", " ", "'" + @"\""" + installSettings.ExecutablePath.FullPath + @"\"" " + pathArgs.Replace("\"", "\\\"") + "'")
.AppendSwitchQuoted("DisplayName=", " ", installSettings.DisplayName)
.AppendSwitchQuoted("start=", " ", installSettings.StartMode);
//.AppendSwitchQuoted("obj=", " ", installSettings.Username)
//.AppendSwitchQuotedSecret("password=", " ", installSettings.Password)
});
StartPowershellScript("& \"sc.exe\" create", createSettings);
var descriptionSettings = new PowershellSettings
{
FormatOutput = true,
LogOutput = true,
OutputToAppConsole = true,
WorkingDirectory = "./"
}.WithArguments(args =>
{
args
.AppendQuoted(installSettings.ServiceName)
.AppendQuoted(installSettings.Description);
});
StartPowershellScript("& \"sc.exe\" description", descriptionSettings);
});
========================================
Install-Commands-Service
========================================
The service pms.uninodecommands.bizname is not installed!
Executing: & "sc.exe" create "pms.uninodecommands.bizname" binPath= '\"C:/dev/test/PMS.UniNodeCommands/PMS.UniNodeCommands.exe\" \"Biz\"' DisplayName= "PMS Commands Service BizName" start= "auto"
[SC] CreateService SUCCESS
Executing: & "sc.exe" description "pms.uninodecommands.bizname" "PMS Commands Service BizName"
[SC] ChangeServiceConfig2 SUCCESS
Let me know what you think so I can do a PR.
Thank you!
SharpeRAD commented
Resolved in v0.3.5