当前位置: 首页>>代码示例>>Python>>正文


Python _winreg.CreateKeyEx方法代码示例

本文整理汇总了Python中_winreg.CreateKeyEx方法的典型用法代码示例。如果您正苦于以下问题:Python _winreg.CreateKeyEx方法的具体用法?Python _winreg.CreateKeyEx怎么用?Python _winreg.CreateKeyEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在_winreg的用法示例。


在下文中一共展示了_winreg.CreateKeyEx方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: set_value

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CreateKeyEx [as 别名]
def set_value(self, value_name, value):
        with winreg.CreateKeyEx(self._root, self.subkey, 0, winreg.KEY_WRITE | self._flags) as key:
            if value is None:
                winreg.DeleteValue(key, value_name)
            elif isinstance(value, str):
                winreg.SetValueEx(key, value_name, 0, winreg.REG_SZ, value)
            else:
                raise TypeError('cannot write {} to registry'.format(type(value))) 
开发者ID:sarugaku,项目名称:pythonfinder,代码行数:10,代码来源:_registry.py

示例2: _set_all_values

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CreateKeyEx [as 别名]
def _set_all_values(self, rootkey, name, info, errors):
        with winreg.CreateKeyEx(rootkey, name, 0, winreg.KEY_WRITE | self._flags) as key:
            for k, v in info:
                if isinstance(v, PythonWrappedDict):
                    self._set_all_values(key, k, v._items(), errors)
                elif isinstance(v, dict):
                    self._set_all_values(key, k, v.items(), errors)
                elif v is None:
                    winreg.DeleteValue(key, k)
                elif isinstance(v, str):
                    winreg.SetValueEx(key, k, 0, winreg.REG_SZ, v)
                else:
                    errors.append('cannot write {} to registry'.format(type(v))) 
开发者ID:sarugaku,项目名称:pythonfinder,代码行数:15,代码来源:_registry.py

示例3: add_registry_keys

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CreateKeyEx [as 别名]
def add_registry_keys():
    for key in get_local_machine_registry_subkeys(KHRONOS_REG_PATH):
        if key is not None:
            key = RegistryKey(key[0], key[2], key[1])
            if key in KEYS_NEEDED:
                KEYS_NEEDED.remove(key)
            else:
                # print("?: "+str(key))
                pass

    # print("No keys left\nKeys to add: "+str(KEYS_NEEDED))

    for key_needed in KEYS_NEEDED:
        try:
            try:
                subkey = winreg.CreateKeyEx(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_CREATE_SUB_KEY)
            except WindowsError as error: 
                print("Couldn't create subkeys at: %s\tReason: %s" % (KHRONOS_REG_PATH, error))
                exit(1)
            finally:
                subkey.Close()
            with winreg.OpenKey(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_WRITE) as key: 
                winreg.SetValueEx(key, key_needed.name, 0, key_needed.data_type, key_needed.value)
                # print("+"+str(key_needed))
        except WindowsError as error:
            print("Couldn't create (%s)\tReason: %s" % (key_needed, error))
            exit(1)

# TODO: How to Enumerate Vendor ICDs on Windows: https://github.com/KhronosGroup/OpenCL-Docs/blob/master/ext/cl_khr_icd.txt#L68
# SEARCH_HIVE=winreg.HKEY_LOCAL_MACHINE 
开发者ID:dthpham,项目名称:butterflow,代码行数:32,代码来源:__init__.py

示例4: r_reg_write_value

# 需要导入模块: import _winreg [as 别名]
# 或者: from _winreg import CreateKeyEx [as 别名]
def r_reg_write_value(r_key=None, r_value=None):
    """Write R registry values."""
    # keys to write
    r_write_keys = ('InstallPath', 'Current Version')
    if r_key not in r_write_keys:
        log.warn("asked to write an invalid key, {}".format(r_key))
        return None

    root_keys = OrderedDict((
        # try HKLM, then HKCU
        ('HKLM', winreg.HKEY_LOCAL_MACHINE),
        ('HKCU', winreg.HKEY_CURRENT_USER)
    ))
    # only work with the R and R64 hives, ArcGIS doesn't examine R32
    r_reg_paths = ["SOFTWARE\\R-core\\R",
                   "SOFTWARE\\R-core\\R64",
                   "SOFTWARE\\Wow6432Node\\R-Core\\R",
                   "SOFTWARE\\Wow6432Node\\R-Core\\R64"]

    for (key_name, root_key) in list(root_keys.items()):
        wrote = False
        for r_path in r_reg_paths:
            r_reg = None

            try:
                log.info("CreateKeyEx on {}\\{}, with write".format(
                    key_name, r_path))
                r_reg = winreg.CreateKeyEx(root_key, r_path, 0, FULL_ACCESS)
            except WindowsError as error:
                if error.errno == errno.ENOENT:
                    pass
                # permission denied, skip
                if error.errno == errno.EACCES:
                    log.debug("permission denied.")
                    continue

            if r_reg:
                try:
                    log.info('setting "{}" to "{}"'.format(r_key, r_value))
                    winreg.SetValueEx(r_reg, r_key, 0,
                                      winreg.REG_SZ, r_value)
                    wrote = True
                except fnf_exception as error:
                    handle_fnf(error)
        # only enter the keys into one hive
        if wrote:
            break 
开发者ID:R-ArcGIS,项目名称:r-bridge-install,代码行数:49,代码来源:rpath.py


注:本文中的_winreg.CreateKeyEx方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。