Jakub Bláha
Jakub Bláha

Reputation: 1609

How to decode registry value using winreg

I have this code

from winreg import *
aReg=ConnectRegistry(None, HKEY_CURRENT_USER)
aKey=OpenKey(aReg, 'Software\Microsoft\Windows\CurrentVersion\Explorer\Accent')
aKey=EnumValue(aKey, 0)
print(aKey[1])

And when I run it, it returns this b'\xb3\xec\xff\x00\x80\xe0\xff\x00Y\xd6\xff\x00)\xa4\xcc\x00\x00s\x99\x00\x00Ws\x00\x00:M\x00\x88\x17\x98\x00'

but in registry editor, it looks like this:

enter image description here

I want to ask, how to decode the first to second.
Thanks for any reply. :)

Upvotes: 1

Views: 2297

Answers (2)

Jakub Bláha
Jakub Bláha

Reputation: 1609

I wrote this, works :)

from winreg import *

def getAccentColor():  
    """
    Return the Windows 10 accent color used by the user in a HEX format
    """
    registry = ConnectRegistry(None,HKEY_CURRENT_USER)
    key = OpenKey(registry, r'SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent')
    key_value = QueryValueEx(key,'AccentColorMenu')
    accent_int = key_value[0]
    accent = accent_int-4278190080
    accent = str(hex(accent)).split('x')[1]
    accent = accent[4:6]+accent[2:4]+accent[0:2]
    return '#'+accent

Upvotes: 0

Martin Evans
Martin Evans

Reputation: 46759

If you want a particular value (rather than enumerating each value one at a time), you can use the QueryValueEx() function as follows:

from winreg import *

hreg = ConnectRegistry(None, HKEY_CURRENT_USER)
hkey = OpenKey(hreg, 'Software\Microsoft\Windows\CurrentVersion\Explorer\Accent')
accent_color_menu = QueryValueEx(hkey, 'AccentColorMenu')[0]
CloseKey(hkey)

print(accent_color_menu)

This would give you something like:

4292311040

Upvotes: 2

Related Questions