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

前端 未结 3 1678
别跟我提以往
别跟我提以往 2020-12-18 00:53

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

相关标签:
3条回答
  • 2020-12-18 01:02

    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 讨论(0)
  • 2020-12-18 01:03

    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.

    0 讨论(0)
  • 2020-12-18 01:23

    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

    0 讨论(0)
提交回复
热议问题