简体   繁体   English

在继续操作之前,如何让PowerShell等到命令完成?

[英]How can I make PowerShell wait until a command is complete before proceeding?

I'm using the following line to uninstall office 2007 based on its Product ID 我正在使用以下行根据其产品ID卸载office 2007

Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/uninstall {90120000-0030-0000-0000-0000000FF1CE}"

I'd like to force a reboot after the uninstall is complete however using -Wait or piping the results to Out-Null don't wait until the uninstall is complete before processing the next line which is a restart. 我想在卸载完成后强制重新启动,但是使用-Wait或将结果传递给Out-Null不要等到卸载完成后再处理下一行重启。 I've also tried using cmd to uninstall but with the same result. 我也尝试使用cmd卸载但结果相同。

cmd /c "msiexec.exe /uninstall {90120000-0030-0000-0000-0000000FF1CE}"

Is there any way to force powershell to wait until the uninstall is complete before processing the Restart-Computer command? 在处理Restart-Computer命令之前,有没有办法强制PowerShell等到卸载完成? I was thinking possibly writing something that detects when the setup.exe process stops before proceeding to the restart? 我想可能会写一些东西来检测setup.exe进程何时停止然后再继续重启?

Start-Process has a wait parameter: Start-Process有一个wait参数:

Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/uninstall {90120000-0030-0000-0000-0000000FF1CE}" -wait

The solution to restart after an misexec.exe uninstallation is to add the /forcerestart parameter to the msiexec call instead of trying to restart in powershell (Credits to Matt): 卸载misexec.exe后重新启动的解决方案是将/forcerestart参数添加到msiexec调用,而不是尝试在powershell中重新启动(Credits to Matt):

Start-Process C:\Windows\System32\msiexec.exe -ArgumentList @("/uninstall {90120000-0030-0000-0000-0000000FF1CE}", "/forcerestart")

My suggestion for this is to actually get the Office Removal Tool from Microsoft and extract the VBS script from it. 我的建议是实际从Microsoft获取Office删除工具并从中提取VBS脚本。 Run that in a Start-Process with the -wait argument, and reboot afterwards. 使用-wait参数在Start-Process中运行它,然后重新启动。 It will not only attempt to gracefully remove Office with msiexec as you are doing, it will also go back and clean up any straggling files or registry entries in case the application is corrupt and will not uninstall nicely. 它不仅会尝试使用msiexec正常删除Office,它还会返回并清理任何分散的文件或注册表项,以防应用程序损坏并且不会很好地卸载。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 Windows Powershell 中,如何等待事件为真再继续? - In Windows Powershell, how can I wait for an event to be true before proceeding? powershell在继续之前等待命令完成 - powershell wait for command to finish before proceeding 在继续之前,如何让Powershell等到命令完成? - How do I make Powershell wait until a command is done before continuing? 在Powershell中执行下一条命令之前,请等待命令完成 - Wait for command to complete before executing next command in powershell 如何在PowerShell中从指定目录运行命令并等待其完成后再继续? - How run a command in PowerShell from a specified directory and wait for it to complete before moving on? Sitecore PowerShell 等待 Show-ListView 模式关闭后再继续 - Sitecore PowerShell wait for Show-ListView modal to close before proceeding 如何使Powershell等待内部命令完成? - How to make Powershell wait on internal command to finish? 如何强制Powershell脚本等待重写文件,直到另一个进程完成读取它为止? - How can I force a Powershell script to wait overwriting a file until another process is finished reading it? 等待直到在Powershell中完成上一个命令 - Wait until previous command is completed in powershell 如何在执行前预览 PowerShell 命令? - How can I preview the PowerShell command before execute?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM