5
sc create
をpowershellスクリプトから呼び出すとします。ここにコードがあります。powershellスクリプトからsc createを呼び出すにはどうすればいいですか?
Set-Content : A positional parameter cannot be found that accepts argument 'binpath='.
At line:1 char:1
問題はどのようなものです:次のエラーを与える
function Execute-Command
{
param([string]$Command, [switch]$ShowOutput=$True)
echo $Command
if ($ShowOutput) {
Invoke-Expression $Command
} else {
$out = Invoke-Expression $Command
}
}
$cmd="sc create `"$ServiceName`" binpath= `"$TargetPath`" displayname= `"$DisplayName`" "
Execute-Command -Command:$cmd
?位置的な議論は何ですか?
コマンドの=記号の後にはスペースを入れないでください。 – AutomatedOrder
エラーが示す通り、 'sc'は' Set-Content'のエイリアスです。 'sc.exe'フルファイル名を使用する –
PS4以降、' New-Service'コマンドレットを使うことができますhttps://technet.microsoft.com/en-us/library/hh849830(v=wps.630).aspx – sodawillow