本文整理汇总了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)))
示例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)))
示例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
示例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