zoukankan      html  css  js  c++  java
  • python _winreg模块

    详细资料请参考:https://docs.python.org/2/library/_winreg.html

    一、常用函数功能介绍

    OpenKey() - 打开一个key

    ##################################################################################################################

    _winreg.OpenKey(keysub_key[, res[, sam]])

      key is an already open key, or any one of the predefined HKEY_* constants.  #注册表中有六大键根,HKEY_USERS,HKEY_CURRENT_USER,HKEY_CURRENT_CONFIG,HKEY_CLASSES_ROOT,HKEY_LOCAL_MACHINE,HKEY_DYN_DATA

      sub_key is a string that identifies the sub_key to open.             #需要操作的子键

      res is a reserved integer, and must be zero. The default is zero.        #必须为0

      #sam默认为只读模式,常用有三个_winreg.KEY_ALL_ACCESS,_winreg.KEY_WRITE,_winreg.KEY_READ

      sam is an integer that specifies an access mask that describes the desired security access for the key. Default is KEY_READ. See Access Rights for other allowed values.    

    ##################################################################################################################
    CloseKey() – 关闭一个Key

    import _winreg as wg
    key_test = wg.OpenKey(wg.HKEY_CURRENT_USER,r"SoftwareMicrosoftWindowsCurrentVersionExplorer")
    wg.CloseKey(key_test)

    CreateKey() – 创建一个Key
    DeleteKey() – 删除一个Key

    import _winreg as wg
    key_test = wg.OpenKey(wg.HKEY_CURRENT_USER,r"SoftwareMicrosoftWindowsCurrentVersionExplorer")
    wg.CreateKey(key_test,'hester')
    wg.CloseKey(key_test)

    继续创建子键

    import _winreg as wg
    key_test = wg.OpenKey(wg.HKEY_CURRENT_USER,r"SoftwareMicrosoftWindowsCurrentVersionExplorerhester")
    wg.CreateKey(key_test,'sub_hester')
    wg.CloseKey(key_test)

    创建键值数据项

    import _winreg as wg
    key_test = wg.OpenKey(wg.HKEY_CURRENT_USER,r"SoftwareMicrosoftWindowsCurrentVersionExplorerhestersub_hester")
    wg.SetValueEx(key_test,'data','',wg.REG_SZ,'0') 
    wg.CloseKey(key_test)

    修改键值数据项

    ##################################################################################################################

    _winreg.SetValueEx(keyvalue_namereservedtypevalue)

      key is an already open key, or one of the predefined HKEY_* constants.

      value_name is a string that names the subkey with which the value is associated.

      type is an integer that specifies the type of the data. See Value Types for the available types.    #类型较多不一一列举,请参考https://docs.python.org/2/library/_winreg.html#value-types

      reserved can be anything – zero is always passed to the API.

      value is a string that specifies the new value.

    ##################################################################################################################

    import _winreg as wg
    key_test = wg.OpenKey(wg.HKEY_CURRENT_USER,r"SoftwareMicrosoftWindowsCurrentVersionExplorerhestersub_hester")
    wg.SetValueEx(key_test,'data','',wg.REG_SZ,'1')
    wg.CloseKey(key_test)

    获取键值数据项值

    import _winreg as wg
    key_test = wg.OpenKey(wg.HKEY_CURRENT_USER,r"SoftwareMicrosoftWindowsCurrentVersionExplorerhestersub_hester")
    wg.QueryValueEx(key_test,'data')
    value,type = wg.QueryValueEx(key_test,'data')

    删除键值数据项

    import _winreg as wg
    key_test = wg.OpenKey(wg.HKEY_CURRENT_USER,r"SoftwareMicrosoftWindowsCurrentVersionExplorerhestersub_hester",0,wg.KEY_WRITE)
    wg.DeleteValue(key_test,'data')
    wg.CloseKey(key_test)

    输入、输出值文件

    LoadKey() – 从指定文件读入键信息

    SaveKey() – 保存键到文件

    刷新注册表

    FlushKey() – 回写所有的键属性改变到注册表

    链接到其他机器的注册表

    ConnectRegistry() – 链接到其他机器的注册表

  • 相关阅读:
    apicloud入门学习笔记1:简单介绍
    QT入门学习笔记1:为什么要选QT及QT软件下载
    Altium Designer入门学习笔记1.软件安装与资料收集
    win 下安装mysql 服务
    几秒后跳转到新页面
    计算3天的日期
    alibaba json
    WebService和Rest Service
    count(*),count(1)和count(主键)的区别
    mybatis替换符号
  • 原文地址:https://www.cnblogs.com/hester/p/7590358.html
Copyright © 2011-2022 走看看