• 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() – 链接到其他机器的注册表

  • 相关阅读:
    栅格数据中加入可见水印
    DWT在栅格数据嵌入不可见水印的应用
    栅格数据嵌入不可见水印的流程
    栅格数据嵌入不可见水印的方法总结
    QIM量化
    哈希函数(hash函数)
    IDEA——IDEA使用Tomcat服务器出现乱码问题
    Quartz学习——SSMM(Spring+SpringMVC+Mybatis+Mysql)和Quartz集成详解(四)
    Quartz学习——Spring和Quartz集成详解(三)
    Quartz学习——Quartz简单入门Demo(二)
  • 原文地址:https://www.cnblogs.com/hester/p/7590358.html
Copyright © 2020-2023  润新知