SC 创建 binpath 错误

Kan*_*shi 17 windows service

我正在尝试在 PowerShell 中运行以下命令

sc create StrongSwan binpath= "C:\Users\Kanishk\Desktop\Strong\Strong\stronswan\strongswan-5.6.3\src\charon-svc\charon-svc.exe"
Run Code Online (Sandbox Code Playgroud)

我已经检查了 .exe 的路径是否正确,我也可以 cd 到它。作为参考,我正在关注这个:https : //wiki.strongswan.org/projects/strongswan/wiki/Charon-svc

我收到以下错误:

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
Run Code Online (Sandbox Code Playgroud)

所以我的问题是相同的命令在 cmd 上运行,但不在 PowerShell 上运行。有什么原因吗?

小智 57

我也遇到了这个。看起来错误发生在 line:1 char:1。所以我认为它不明白“sc”是什么。所以我改成sc create ..sc.exe create ..,它对我的​​服务有用。

  • 使用 Powershell 时需要这个 .exe 东西,但使用 cmd 它可以工作。 (9认同)

fle*_*erb 6

我也用 Powershell 遇到了这个问题。

扩展答案:

“sc”是 Powershell 中“Set-Content”的别名,它在您的输出和 Powershell“Get-Alias”命令中得到确认。这就是 sc 失败但 sc.exe 成功的原因,以及 sc 在 cmd 中工作而在 powershell 中失败的原因。