本文整理匯總了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)))
示例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: _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
示例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
示例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