python读取注册表中值的方法
在Python的标准库中,_winreg.pyd可以操作Windows的注册表,另外第三方的win32库封装了大量的Windows API,使用起来也很方便。不过这里介绍的是使用_winreg操作注册表,毕竟是Python自带的标准库,无需安装第三方库。 下面的例子是通过Python获取Windows XP下已经安装的补丁号。Windows的补丁号都在“HKEY_LOCAL_MACHINESOFTWAREMicrosoftUpdates”下,通过循环下面所有的目录节点,如果找到的名称符合正则表达式KB(d{6}).*,则表示是一个补丁号。 从例子可以看出操作起来非常的简单和快速。 复制代码 代码如下: # -*- coding: utf-8 -*- # 获取Windows的已打的补丁号 from _winreg import * def subRegKey(key,pattern,patchlist): if __name__ == '__main__': 下面内容转自 Python Standard Library12.13 The _winreg Module (Windows only,New in 2.0) The _winreg module provides a basic interface to the Windows registry database. Example 12-17 demonstrates the module. Example 12-17. Using the _winreg Module 复制代码 代码如下: import _winreg explorer = _winreg.OpenKey( #list values owned by this registry key value,type = _winreg.QueryValueEx(explorer,"Logon User Name") print
user is u'Effbot' 您可能感兴趣的文章:
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |