SC 创建二进制路径错误



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

sc create StrongSwan binpath= "C:UsersKanishkDesktopStrongStrongstronswanstrongswan-5.6.3srccharon-svccharon-svc.exe"

我已经检查了通往.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:UsersKanishkDesktopStrongStrong ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : InvalidArgument: (:) [Set-Content], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.SetContentCommand

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

我也遇到了这个问题。看起来错误发生在行:1 字符:1。所以我假设它不明白"sc"是什么。所以我把sc create ..改成了sc.exe create ..,它对我的服务有用。

我在Powershell上也遇到了这个问题。

要扩展答案:

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

我尝试了一段时间的Powershell,但没有用。我想也许可以在命令提示符上尝试一下(作为管理员(。[SC] CreateService SUCCESS

使用 Powershell -> 以管理员身份运行

sc.exe create TestService binPath= "D:\Windows Services\TestService\TestService.exe">

如果路径在 " 之间包含空格,则可能必须将路径放在 " 下

PowerShell中的SCSet-Content命令的别名,与Windows服务管理无关,不会触发服务控制可执行文件sc.exe

若要在 PowerShell 中创建新的 Windows 服务,可以使用New-Service命令(需要管理员权限 =>">管理员身份运行"(:

> New-Service MyService "C:/the/path/to/myservice.exe"
Status   Name      DisplayName
------   ----      -----------
Stopped  MyService MyService

相关内容

最新更新