如何确定我刚安装的 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 13:24:00  来源:igfitidea点击:

How to find out if an MSI I just installed requested a Windows reboot?

c#windowsinstallerwindows-installer

提问by Nestor

I've built a setup.exein 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.Processto run the MSIs and after the process has exited, you would retrieve the processes exit code using the ExitCodeproperty (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.ProcessMSI 并且在进程退出后,您将使用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 $rebootPendingequalling $trueindicates that a system reboot is pending for anyreason, not just due to MSI-based installations.

请注意,$rebootPending等于$true表示系统重新启动因任何原因而未决,而不仅仅是由于基于 MSI 的安装。