Reputation: 568
I am trying to run the following command in the PowerShell
sc create StrongSwan binpath= "C:\Users\Kanishk\Desktop\Strong\Strong\stronswan\strongswan-5.6.3\src\charon-svc\charon-svc.exe"
I have checked the path to the .exe is correct and I can cd to it also. For reference I am following this: https://wiki.strongswan.org/projects/strongswan/wiki/Charon-svc
I am receiving the following error:
Set-Content : A positional parameter cannot be found that accepts argument 'binpath='.
At line:1 char:1
+ sc create NewService binpath= C:\Users\Kanishk\Desktop\Strong\Strong\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand
So my problem is the same command is working on cmd but not on PowerShell. Any reasons why?
Upvotes: 33
Views: 25033
Reputation: 13364
SC
in PowerShell is an alias for the Set-Content
command which is unrelated to Windows services management, and won't trigger the Service Control executable sc.exe
.
To create a new Windows service in PowerShell you can use the New-Service
command (requires Administrator privileges => "Run as administrator"):
> New-Service MyService "C:/the/path/to/myservice.exe"
Status Name DisplayName
------ ---- -----------
Stopped MyService MyService
Upvotes: 1
Reputation: 136
Use Powershell -> Run As Administrator
sc.exe create TestService binPath= "D:\Windows Services\TestService\TestService.exe"
may have to put path under "" if it contains spaces in between
Upvotes: 1
Reputation: 143
I was trying with powershell for a while but it didn't work. I thought maybe try it on Command Prompt (as an admin).
[SC] CreateService SUCCESS
Upvotes: 2
Reputation: 743
I ran into this with Powershell as well.
To expand on the answer:
"sc" is an alias in Powershell for "Set-Content" which is confirmed in your output and by the Powershell "Get-Alias" command. That's why sc fails but sc.exe is successful, and why sc works in cmd and fails in powershell.
Upvotes: 13
Reputation: 1226
I ran into this also. It looks like the error happens at line:1 char:1. So I assumed it doesn't understand what "sc" is. So I changed sc create ..
to sc.exe create ..
and it worked for my service.
Upvotes: 121