我在将引号放在引号中时遇到问题

yan布

我正在尝试在PowerShell中执行一行命令来下载音乐文件并每1小时执行一次,
Start-Process -WindowStyle Hidden PowerShell "Register-ScheduledTask Regedit -Action (New-ScheduledTaskAction -Execute PowerShell -Argument "Start-process -WindowStyle Hidden PowerShell '(New-Object System.Media.SoundPlayer C:\Windows\Jjgw.wav).PlaySync()'") -Trigger (New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 1)) -f;(New-Object System.Net.WebClient).DownloadFile('https://github.com/User/Repository/raw/master/Music.wav','C:\Windows\Music.wav')"
但我只是无法设置单引号/双引号来转到最后一个引号,而只能使用最接近的引号。
我正在尝试达到以下目的:
PowerShell ""command1";"command2""
只执行这两个命令。

行军

这经常被问到。最好的方法是使用EncodedCommand

$command = {
    $action = New-ScheduledTaskAction -Execute PowerShell -Argument "Start-process -WindowStyle Hidden PowerShell '(New-Object System.Media.SoundPlayer C:\Windows\Jjgw.wav).PlaySync()'"
    $trigger = New-ScheduledTaskTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Hours 1)
    Register-ScheduledTask Regedit -Action $action -Trigger $trigger -Force
    (New-Object System.Net.WebClient).DownloadFile('https://github.com/User/Repository/raw/master/Music.wav','C:\Windows\Music.wav')
}
$encodedCommand = [convert]::ToBase64String([System.Text.encoding]::Unicode.GetBytes($command.ToString())) 
Start-Process -WindowStyle Hidden PowerShell -ArgumentList "-EncodedCommand", $encodedCommand

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章