powershell - 隐藏的 sleep 屏幕

标签 powershell

我试图停止一个进程,然后休眠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/

相关文章:

powershell - 使用 Select-Object 在 PowerShell 中过滤子对象

powershell - 通过管道传递脚本 block

.net - 如何从powershell构建VS解决方案文件夹

windows - 设置 Windows PowerShell 环境变量

linux - 如何使用 Azure powershell 脚本从 ubuntu 虚拟机下载文件

PowerShell 脚本在本地运行,但远程出错

azure - 术语 'az' 未被识别为 cmdlet、函数、脚本文件或可操作程序的名称

powershell - 后台作业过早结束

powershell - 提供凭据时启动进程引发错误 - 可能的错误

c# - `Add-Type` C# 6+ 功能抛出错误