通過Python的內置模塊winreg這里主要給出一些winreg的Demo代碼
Python2:import _winreg、Python3:import winreg
#!python37
# -*- coding: utf-8 -*-
# coding:utf-8
import winreg
def obtain():
# 獲取該鍵的所有鍵值
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\\Inspiry\\BasePay\\Address")
# 獲取該鍵的所有鍵值,遍歷枚舉
try:
i = 0
while 1:
# EnumKey用來枚舉子鍵,EnumValue方法用來枚舉鍵值,
name, value, type1 = winreg.EnumValue(key, i)
# print(repr(name),value)
return value
i +=1
except WindowsError:
print('error')
if __name__ == '__main__':
obtain()