13

I am working on a project where several software and drivers are installed on a windows 7 PC. This shall work without user inputs.

Now there is the question: How can I determine in this program if a reboot is required to finish an installation (can be driver or software).

We are working on Windows 7 embedded and there is no taskbar enabled or any tooltips or something like this visible. Software is installed in silent mode.

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
hoffmanuel
  • 403
  • 1
  • 5
  • 14

3 Answers3

16

Use the following registry key:

HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations

Source: How to find out if an MSI I just installed requested a windows reboot?

As discovered by the asker of this question HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending shows when a reboot is pending on the machine as long as the OS is Vista or newer.

Community
  • 1
  • 1
Pete Garafano
  • 4,863
  • 1
  • 23
  • 40
  • Is this working for drivers, too? Just to know it, because I have read that it is not 100% sure ^^ Thanks anyways – hoffmanuel Mar 18 '13 at 16:47
  • I would assume it depends on how the drivers are installed. What I recommend is you check that registry on your embedded system after the installation is completed. If the key does not provide the information you are looking for, update the question with the new information. – Pete Garafano Mar 18 '13 at 16:51
  • All drivers are installed directly via inf, using pinvoke and DiInstallDriver function from newdev api. Ok thanks I will try that and get back with further information. – hoffmanuel Mar 19 '13 at 07:08
  • 2
    I have found some writing that beginning from Vista there is also a `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending` Key available as well as `HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired` besides your specified one. I will see, how they work – hoffmanuel Mar 19 '13 at 09:12
  • I have tried a combination of all three methods and got a reboot required after performing an operation, that required a reboot The `RebootPending`Key of `Component Based Servicing` only works for Vista+ OS – hoffmanuel Mar 20 '13 at 07:08
  • 4
    Check "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\" if a subkey named "RebootRequired" is present. Check "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\" if a subkey named "RebootRequired" is present. Check "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\" if a value "PendingFileRenameOperations" if present. If any of these conditions are met, a reboot is required. – hoffmanuel Nov 09 '15 at 08:02
  • 1
    @hoffmanuel RebootPending not RebootRequired for "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\". Can you fix this typo please in previous comment? – Ainullin Damir Aug 17 '18 at 13:58
  • You are right. Unfortunately I do not seem to be able to modify the comment :/ – hoffmanuel Aug 31 '18 at 12:01
2

After a long research I found a way how to query pending restarts with a native Windows DLL directly in a .NET application. The main problem is that there can be many reasons why Windows has to restart. In addition, the Windows version sometimes also plays a role.

During the research I came across an article describing various scripts in the Windows Update environment, such as determining whether the automatic updates service is enabled or a computer needs to be rebooted. There you will find a reference to the Microsoft.Update.SystemInfo Object, which finally led to ISystemInformation interface having the method ISystemInformation::get_RebootRequired (Gets a Boolean value that indicates whether a system restart is required to complete the installation or uninstallation of one or more updates.).

For more details about the journey, see my blog post Determine programmatically pending reboot status for a Windows machine in C# and PowerShell

Stefan Prugg
  • 264
  • 2
  • 4
0

The "PendingReboot" module incorporates all the mentioned tests (+ CCM WMI probe) into a single convenient cmdlet to reliably detect pending reboot:

# Install
Install-Module -Name PendingReboot

# Run
Test-PendingReboot -Detailed
George Chakhidze
  • 1,269
  • 12
  • 15