如何确定我刚安装的 MSI 是否要求重新启动 Windows?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1685821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to find out if an MSI I just installed requested a Windows reboot?
提问by Nestor
I've built a setup.exe
in C# that runs several chained MSI's (with the /QUIET /NORESTART
). At the end I'd like to check if a reboot is needed in the machine (that is, if one of the MSI's requested a reboot).
我setup.exe
在 C# 中构建了一个运行多个链接的 MSI(带有/QUIET /NORESTART
)。最后,我想检查机器是否需要重新启动(即,是否有一个 MSI 请求重新启动)。
How can I detect so?
我怎么能检测到呢?
采纳答案by Vinko Vrsalovic
The following registry location has the information:
以下注册表位置包含信息:
Key HKLM\System\CurrentControlSet\Control\Session Manager
, value PendingFileRenameOperations
键HKLM\System\CurrentControlSet\Control\Session Manager
,值PendingFileRenameOperations
Source: http://technet.microsoft.com/en-us/sysinternals/bb897556.aspx
来源:http: //technet.microsoft.com/en-us/sysinternals/bb897556.aspx
回答by bsara
Another way to accomplish this is to check the exit codes of all of the MSIs that you run in your code. If an MSI has an exit code of 3010 then it requires a reboot.(http://msdn.microsoft.com/en-us/library/aa368542.aspx).
Assuming that you're using System.Diagnostics.Process
to run the MSIs and after the process has exited, you would retrieve the processes exit code using the ExitCode
property (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.exitcode(v=vs.90).aspx).
So, you can simply check the exit code of an MSI process and when you're done running all of your MSIs, if any of them returned 3010 then you know you need to reboot.
实现此目的的另一种方法是检查您在代码中运行的所有 MSI 的退出代码。如果 MSI 的退出代码为 3010,则需要重新启动。(http://msdn.microsoft.com/en-us/library/aa368542.aspx)。
假设您正在使用System.Diagnostics.Process
MSI 并且在进程退出后,您将使用ExitCode
属性 ( http://msdn.microsoft.com/en-us/library/system.diagnostics.process.txt)检索进程退出代码。退出代码(v=vs.90).aspx)。
因此,您可以简单地检查 MSI 进程的退出代码,当您运行完所有 MSI 后,如果其中任何一个返回 3010,那么您就知道需要重新启动。
回答by mklement0
To complement Vinko Vrsalovic's helfpul answerwith a PowerShellcommand:
使用PowerShell命令补充Vinko Vrsalovic 的 helfpul 答案:
$rebootPending = $null -ne
(Get-ItemProperty 'HKLM:\System\CurrentControlSet\Control\Session Manager').PendingFileRenameOperations
Note that $rebootPending
equalling $true
indicates that a system reboot is pending for anyreason, not just due to MSI-based installations.
请注意,$rebootPending
等于$true
表示系统重新启动因任何原因而未决,而不仅仅是由于基于 MSI 的安装。