python3 操作注册表


1.1 读取   
import winreg 

key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,r"Software\Microsoft\Windows\CurrentVersion\Explorer") #获取该键的所有键值,因为没有方法可以获取键值的个数,所以只能用这种方法进行遍历   try: 
    i = 0 while 1: #EnumValue方法用来枚举键值,EnumKey用来枚举子键  name, value, type = winreg.EnumValue(key, i) print repr(name),
         i += 1 except WindowsError: print #如果知道键的名称,也可以直接取值  value, type = winreg.QueryValueEx(key, "EnableAutoTray")

 


 1.2 创建、修改  

import winreg 

key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,r"Software\Microsoft\Windows\CurrentVersion\Explorer") #删除键  winreg.DeleteKey(key, "Advanced") #删除键值  winreg.DeleteValue(key, "IconUnderline") #创建新的键  newKey = winreg.CreateKey(key,"MyNewkey") #给新创建的键添加键值  winreg.SetValue(newKey,"ValueName",0,"ValueContent")


 
 1.3 访问远程注册表 
 #第二参数必须是HKEY_CURRENT_USER、HKEY_LOCAL_MACHINE等预先定义好的值,拿到返回的key后就可以进行操作了

 key = winreg.ConnectRegisty("IP地址或者机器名",winreg.HKEY_CURRENT_USER)
本博客所有文章如无特别注明均为原创。作者:果果 ,复制或转载请以超链接形式注明转自 冰寒吧 。
原文地址《python3 操作注册表》

相关推荐

网友评论(0)