开发者

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

开发者 https://www.devze.com 2022-12-10 04:55 出处:网络
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 开发者_StackOverflow(that is, if one of

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 开发者_StackOverflow(that is, if one of the MSI's requested a reboot).

How can I detect so?


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消