import _winreg
# 获取注册表信息
def getToken(username):
try:
# 第二个参数为本地注册表信息路径
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r"Software\aaa\bbb"+username)
i = 0
while True:
try:
k, v, t = _winreg.EnumValue(key, i)
i += 1
except Exception as e:
break
return v
except:
return ''
# 设置注册表信息
def setToken(token,username):
try:
# 设置注册表一级 路径
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, r"Software")
try:
_winreg.DeleteKey(key, "aaa")
except:
pass
# 设置 二级路径
newKey = _winreg.CreateKey(key, "aaa")
# 在其路径下设置 key 和 对应的值
_winreg.SetValue(newKey, "bbb" + username, _winreg.REG_SZ, token)
except:
return ''