當前位置: 首頁>>代碼示例>>Python>>正文


Python winreg.CreateKeyEx方法代碼示例

本文整理匯總了Python中winreg.CreateKeyEx方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.CreateKeyEx方法的具體用法?Python winreg.CreateKeyEx怎麽用?Python winreg.CreateKeyEx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在winreg的用法示例。


在下文中一共展示了winreg.CreateKeyEx方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: _winreg_read

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKeyEx [as 別名]
def _winreg_read(self, base, path, key):
        try:
            if self.is_win_x64:
                hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ | winreg.KEY_WOW64_32KEY)
            else:
                hkey = winreg.CreateKeyEx(base, path, 0, winreg.KEY_READ)

            value = winreg.QueryValueEx(hkey, key)
            return value

        except OSError:
            return None 
開發者ID:tp4a,項目名稱:teleport,代碼行數:14,代碼來源:env.py

示例4: __add_to_startup_programs

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import CreateKeyEx [as 別名]
def __add_to_startup_programs(self):
        '''
        @summary: Adds Crypter to the list of Windows startup programs
        @todo: Code and test
        @todo: Restore try and except catch
        '''

        try:
            reg = winreg.CreateKeyEx(winreg.HKEY_CURRENT_USER, self.STARTUP_REGISTRY_LOCATION)
            winreg.SetValueEx(reg, "Crypter", 0, winreg.REG_SZ, sys.executable)
            winreg.CloseKey(reg)
        except WindowsError:
            pass 
開發者ID:sithis993,項目名稱:Crypter,代碼行數:15,代碼來源:Crypter.py

示例5: 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;未經允許,請勿轉載。