如何使用 winreg 解码注册表值
How to decode registry value using winreg
我有这个代码
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])
当我 运行 它时,它 returns 这个 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'
但在注册表编辑器中,它看起来像这样:
我想问一下,如何解码第一到第二
感谢您的回复。 :)
如果您想要一个特定的值(而不是一次枚举每个值),您可以使用 QueryValueEx()
函数,如下所示:
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)
这会给你这样的东西:
4292311040
这是我写的,有效:)
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
我有这个代码
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])
当我 运行 它时,它 returns 这个 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'
但在注册表编辑器中,它看起来像这样:
我想问一下,如何解码第一到第二
感谢您的回复。 :)
如果您想要一个特定的值(而不是一次枚举每个值),您可以使用 QueryValueEx()
函数,如下所示:
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)
这会给你这样的东西:
4292311040
这是我写的,有效:)
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