レジストリからREG_DWORDの変数の値を取得する方法

権利 :

私は(regeditを経由して)Windowsレジストリ内の変数を作成し、持っている私の変数の値を取得したいきたREG_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
モーリス・マイヤー:

私はあなたがQueryValueExを意味推測します:

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

REG値: ここでは、画像の説明を入力します。

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=25921&siteId=1