[英]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.