SharpeRAD/Cake.Services

Operations on Service with name containing '$' character fail

Closed this issue · 3 comments

I have a service, whose name contains dollar sign $.
That's because it's Topshelf service with named instance, so convention there is ServiceName$Instance.

Therefore operating on service using e.g. StopService() is impossible, because it's using quoted arguments, which in powershell are evaluated during execution.

So sc.exe stop MyService$InstanceA in powershell would be evaluated to sc.exe stop MyService;
Evaluation can be prevented using single quotes, or StringLiteralArgument.

Sorry but this addin uses System.ServiceProcess.ServiceController to start / stop services, not Powershell...

I am sure I've seen some code with powershell and sc.exe here... I will check again.

Ok, my bad. It's not Start/Stop but Install/Uninstall methods.

private void PowershellCreateCommand(string computer, InstallSettings settings)

Installing a service with ServiceName = "MyService$InstanceA" actually installs it with name MyService.