I'm not able to read my Windows Key from the registry using winreg

446 Views Asked by At

I've given up trying to do a subprocess check_output with a reg query because some files seem to be "hidden" when using Python, but now I'm getting somewhat of the same issue here.

I have this code:

from winreg import *
location = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
key = OpenKey(location, "SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform")

try:
    for i in range(50):
        print(EnumValue(key, i))
except OSError:
    print("No more data avaiable")

I get this result (I put [censored in there myself]):

('AuthorizedContainers', '[censored]', 1)
('IgnoreContainerOrigin', 0, 4)
('InactivityShutdownDelay', 30, 4)
('KeepRunningThresholdMins', 15, 4)
('NoExpirationUX', 0, 4)
('SkipRearm', 0, 4)
('UserOperations', 0, 4)
('VLActivationInterval', 120, 4)
('VLRenewalInterval', [censored], 4)
No more data avaiable

A lot of entries are missing, and specifically the one I'm trying to get to ("BackupProductKeyDefault") and I have no idea why that's happening.

Here's a comparison of what I got from my code and what is actually in the Registry (red line means I got it in my print result, and the green rectangle is the value I'm fundamentally trying to get): enter image description here

1

There are 1 best solutions below

1
On

it is in different order for some reason

try to do this:

aa = 0
with winreg.ConnectRegistry(None,winreg.HKEY_LOCAL_MACHINE) as hkey:
    with winreg.OpenKey(hkey,'SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform',0,winreg.KEY_ALL_ACCESS) as sub_key:
        for a in range(100):
            print(winreg.EnumValue(sub_key,aa))
            aa +=1