我试图停止一个进程,然后休眠10秒钟,杀死下一个进程再休眠10秒钟,然后启动另一个进程。问题是一切都立即运行。所以我想开始的过程没有运行,因为其他人都没有停止。
Start-Process Powershell.exe -windowstyle Minimized { Stop-Process -processname vpnagent -Force }
Start-Process powershell.exe -windowstyle Minimized { start-sleep -s 10 }
Start-Process Powershell.exe -windowstyle Minimized { Stop-Process -processname vpnui -force }
Start-Process powershell.exe -windowstyle Minimized { start-sleep -s 10 }
Start-Process -filepath "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe" -ArgumentList 'connect company.domain.com' -WindowStyle Minimized
最佳答案
提出这个更简单的代码并解释我的意思的答案:
Stop-Process -ProcessName vpnagent -Force
Start-Sleep -Seconds 10
Stop-Process -ProcessName vpnui -Force
Start-Sleep -Seconds 10
# (to make line shorter)
$path = "C:\Program Files (x86)\Cisco\Cisco AnyConnect Secure Mobility Client\vpncli.exe"
$args = "connect company.domain.com"
Start-Process -FilePath $path -ArgumentList $args -WindowStyle Minimized
编辑:这似乎可以满足您的要求,但是您会看到第一个powershell窗口:
Start-Process powershell.exe -ArgumentList "-File path/to/script.ps1" -WindowStyle Minimized
关于powershell - 隐藏的 sleep 屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41383811/