Get Windows From Registry

Exporting DigitalProductId from the registry. Navigate to the HKEYLOCALMACHINE TEST Microsoft Windows NT CurrentVersion key (you can copy and paste the key name in the key bar under the menu. On the right pane you will see registry values for the selected key and you should see the DigitalProductId value as REGBINARY. Another common Windows registry operation is the enumeration of the values under a given registry key. Windows provides the RegEnumValue API (bit.ly/2jB4kaV) for this purpose. Here, I’ll show how to use this API to get a list of the names and types of the values located under a given registry key, wrapping the enumeration process in a. For a 32-bit application on a 64-bit operating system, you need to get the content of the registry key HKEYLOCALMACHINE SOFTWARE Wow6432Node Microsoft Windows CurrentVersion Uninstall. If an application was installed for the current user, then you can locate it using the following registry key HKCU Software Microsoft Windows CurrentVersion.

Whenever you install software, updates or make configuration changes, it’s common for Windows to need a reboot. Many OS tasks sometimes force Windows to require a reboot. When a reboot is pending, Windows add some registry values to show that. In this blog post, you’re going to learn how to check for a pending reboot and how to build a PowerShell script to automate the task.

Windows Needs Rebooted

When you’re in on the console, you can notice a reboot is pending by some popup box or notification as shown below.

From that notification, you can restart Windows and be done with it. But, what if you can’t immediately reboot a machine when it needs to? What if you’ve just installed updates on a production server and that server can’t be rebooted right now?

The reboot must wait.

Time goes by and by then the reboot may be forgotten about altogether! By the time you realize, many servers or workstations need to be rebooted but which ones?

Pending Reboot Flags are in the Registry

A pending reboot is defined in many places. Scroll right to see the values and conditions. A Windows computer is pending a reboot if any of the conditions in this table are true.

If you have the Microsoft System Center Configuration Manager (SCCM) client installed, you may also see these methods in WMI.

Once you know each method to check for a pending reboot, there are many different ways to check registry values. You could open up regedit.exe and manually mouse through each registry key.

Manually checking via the registry works but we’re human. What if you forget to check one registry path or just forget which ones to check? There’s a much better way to do this. You can create a script or function to do this for you. In my case, I prefer PowerShell so that’s what I’ll use.

By using a PowerShell script, you can query one or all computers in our domain or manually provide the server names to see if they are pending a reboot. You can then make a decision to whether to reboot them then or make a list to reboot later. The choice is yours.

To use my PowerShell method, you’ll need to ensure PowerShell Remoting is set up and available on your servers.

Testing for a a Pending Reboot (The Easy Way)

If you don’t want to learn how to check these registry keys and build a tool like this in PowerShell, I’ve made it easy for you. Simply open up your PowerShell console and type Install-Script Test-PendingReboot. Install-Script will download my PowerShell script from the PowerShell Gallery to C:Program FilesWindowsPowerShellScripts. Then run the script as shown below.

You can provide as many servers as you want via the ComputerName parameter. The script will return True or False along with the server name.

Get Windows 10 Key From Registry

This tool checks all of the registry keys in the above table for you.

If you’d like to add conditions I’ve missed or correct any mistakes I’ve made, feel free to issue a pull request on GitHub to fix it.

If you want to learn how to build a tool like this, read on!

Building a Pending Reboot PowerShell Tool

First, you’ll need to define all of the computers you’d like to test a reboot on. There are many different ways to do this but for this demonstration, I’ll define them manually via an array.

Now create a foreach loop to iterate over each of them.

Next, I recommend using PowerShell Remoting and checking each registry key and value condition inside of a single PSSession. Create a PSSession for every server.

Once you have a PSSession created, you’ll then need to run the checks.

Since you’ll be running many different checks using the same code such as:

  • Testing if a registry key exists
  • Testing if a registry value exists
  • Testing if a registry value is not null

I recommend creating simple functions for each of these checks. This allows you to call a function instead of duplicating code. The Test-PendingReboot script builds all of these helper functions into a single scriptblock as shown below.

Inside of that same scriptblock, define each condition referencing the helper functions you just created.

Get windows 10 key from registry

You can now create a foreach loop inside of your $serversforeach loop that reads each test executes each test.

When you run the code, the script returns an output like this:

Get Windows Password From Registry

You can create this output by ensuring the foreach loop returns a single object per server. You should know that if any of the registry values exist, then the server is pending a reboot. Knowing this, you then need to return True if any of the values exist and False if none of them exist.

Get Windows Password From Registry

Wrap all of this up into a script and it should look like this (with some minor additions like Credential).

Registry

You can now execute it like this:

Get Windows 10 Key From Registry

Summary

You should now have a quick way to test pending reboot across Windows servers. You can see that by using PowerShell, you can consolidate down many tedious steps into one script. This script allows you to quickly test for a pending reboot across many servers at once.

Get Windows Registry Key C#

If you know of any other indications to check for a pending reboot, please let me know.

Get Windows Registry Value

More from Adam The Automator & Friends