Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何从注册表中获取REG_DWORD变量的值_Python_Python 3.x_Winreg - Fatal编程技术网

Python 如何从注册表中获取REG_DWORD变量的值

Python 如何从注册表中获取REG_DWORD变量的值,python,python-3.x,winreg,Python,Python 3.x,Winreg,我已经在Windows注册表中创建了一个变量(通过regedit),并希望获取变量的值,该变量的类型为REG\u DWORD。我使用以下代码获取值: def get_DWORD_val(): from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKey, QueryValue, REG_EXPAND_SZ, REG_SZ try: root = ConnectRegistry(None, H

我已经在Windows注册表中创建了一个变量(通过regedit),并希望获取变量的值,该变量的类型为
REG\u DWORD
。我使用以下代码获取值:

def get_DWORD_val(): 
    from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKey, QueryValue, REG_EXPAND_SZ, REG_SZ
    try:
           root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
           print("---1")
           root_key = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Python', 0, KEY_READ)
           print("---2")
           [Pathname,regtype]=(QueryValue(root_key,"Ver_Tokenlog"))

    except WindowsError:
        return ["Error"]

    return Pathname
输出:

---1
---2
['Error']
将引发此错误:

winerror 2 the system cannot find the file specified

我猜你指的是QueryValuex:

def get_DWORD_val(): 
    from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx, QueryValue, REG_EXPAND_SZ, REG_SZ, KEY_READ

    root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
    print("---1")
    root_key = OpenKey(HKEY_LOCAL_MACHINE, r'SOFTWARE\Python', 0, KEY_READ)
    print("---2")
    Pathname,regtype = QueryValueEx(root_key, "Ver_Tokenlog")
    print(Pathname)
    print(regtype)


get_DWORD_val()
输出为:

---1
---2
256
4
注册值:

发生了什么错误?它无法返回路径名。错误为:winerror 2系统找不到指定的文件