Search code examples
pythonregistrydecodewinreg

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. :)


Solution

  • 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