Python自动化处理注册表的读取和编写操作
发布时间
阅读量:
阅读量
在Windows系统中进行自动化测试时,常常需要处理与注册表相关的读写操作,例如,若需获取某个软件的安装路径,通常会到注册表中的App Paths键值下进行查询,这一过程便涉及注册表的读取功能。此时可借助Python语言提供的_winreg模块来完成相关操作,具体实现代码如下:
def reg_query(path, key):
try:
path = path.replace("/", "\ ")
rootName = path[:path.find("\ ")]
subPath = path[path.find("\ ") + 1:]
rootKey = _query_root(rootName)
if rootKey is None:
return ""
print path
root = _winreg.OpenKey(rootKey, subPath)
value, type = _winreg.QueryValueEx(root, key)
return value
except:
全部评论 (0)
还没有任何评论哟~
