How to find out if an MSI I just installed request

2019-01-19 19:58发布

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).

How can I detect so?

3条回答
在下西门庆
2楼-- · 2019-01-19 20:35

To complement Vinko Vrsalovic's helfpul answer with a PowerShell command:

$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 any reason, not just due to MSI-based installations.

查看更多
\"骚年 ilove
3楼-- · 2019-01-19 20:40

The following registry location has the information:

Key HKLM\System\CurrentControlSet\Control\Session Manager, value PendingFileRenameOperations

Source: http://technet.microsoft.com/en-us/sysinternals/bb897556.aspx

查看更多
孤傲高冷的网名
4楼-- · 2019-01-19 20:42

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.

查看更多
登录 后发表回答