本文整理匯總了Python中winreg.KEY_WRITE屬性的典型用法代碼示例。如果您正苦於以下問題:Python winreg.KEY_WRITE屬性的具體用法?Python winreg.KEY_WRITE怎麽用?Python winreg.KEY_WRITE使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類winreg
的用法示例。
在下文中一共展示了winreg.KEY_WRITE屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: path_cleanup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def path_cleanup():
''' Removes SIMNIBS from PATH '''
if sys.platform in ['linux', 'darwin']:
bashrc, backup_file = _get_bashrc()
if not os.path.isfile(bashrc):
print('Could not find bashrc file')
return
print('Removing SimNIBS install from PATH')
print(f'Backing up the bashrc file at {backup_file}')
_copy_and_log(bashrc, backup_file)
with open(backup_file, 'r') as fin:
with open(bashrc, 'w') as fout:
for line in fin:
if not re.search('simnibs', line, re.IGNORECASE):
fout.write(line)
else:
simnibs_env_vars = _get_win_simnibs_env_vars()
path = _get_win_path()
path = path.split(';')
path = [p for p in path if len(p) > 0]
for key, value in simnibs_env_vars.items():
# If the directory is in the PATH variable, remove it
path = [
os.path.normpath(p) for p in path if not (
os.path.normpath(value) in os.path.normpath(p))]
# Remove environment variable
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
winreg.DeleteValue(reg, key)
# write out the PATH with SimNIBS removed
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
path = ';'.join(path) + ';'
winreg.SetValueEx(reg,'Path', 0, winreg.REG_EXPAND_SZ, path)
示例2: uninstaller_cleanup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def uninstaller_cleanup():
if sys.platform == 'win32':
try:
with winreg.OpenKey(
winreg.HKEY_CURRENT_USER,
r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
access=winreg.KEY_WRITE) as reg:
winreg.DeleteKey(reg, 'SimNIBS')
except FileNotFoundError:
pass
示例3: install
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def install():
if check_installed() is False:
runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Run", 0,
winreg.KEY_WRITE)
winreg.SetValueEx(runkey, "Px", 0, winreg.REG_EXPAND_SZ,
get_script_cmd())
winreg.CloseKey(runkey)
pprint("Px installed successfully")
else:
pprint("Px already installed")
sys.exit()
示例4: uninstall
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def uninstall():
if check_installed() is True:
runkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r"Software\Microsoft\Windows\CurrentVersion\Run", 0,
winreg.KEY_WRITE)
winreg.DeleteValue(runkey, "Px")
winreg.CloseKey(runkey)
pprint("Px uninstalled successfully")
else:
pprint("Px is not installed")
sys.exit()
###
# Attach/detach console
示例5: set_value
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [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)))
示例6: _set_all_values
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [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)))
示例7: open_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def open_key(self, key, subkey):
try:
self.current_key = winreg.OpenKey(self.key, self.subkey, 0, winreg.KEY_WRITE)
to_return = self._return_success(self.current_key)
except Exception as e:
to_return = self._return_error(str(e))
return to_return
示例8: open_key
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def open_key(self, key, subkey):
""" Opens a key
"""
try:
return winreg.OpenKey(key, subkey, 0, winreg.KEY_WRITE)
except:
return None
示例9: path_setup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def path_setup(scripts_dir, force=False, silent=False):
''' Modifies the bash startup path and postpends SimNIBS to the PATH '''
scripts_dir = os.path.abspath(scripts_dir)
silent = silent and GUI
if sys.platform in ['linux', 'darwin']:
bashrc, _ = _get_bashrc()
if os.path.exists(bashrc):
has_simnibs = (
re.search('simnibs', open(bashrc, 'r').read(), re.IGNORECASE)
is not None)
else:
has_simnibs = False
if sys.platform == 'win32':
simnibs_env_vars = _get_win_simnibs_env_vars()
has_simnibs = len(simnibs_env_vars) != 0
if has_simnibs:
if force:
overwrite=True
else:
overwrite = _get_input(
'Found another SimNIBS install, overwite it from the PATH?',
silent)
if not overwrite:
print('Not Adding the current SimNIBS install to the PATH')
return
path_cleanup()
print(f'Postpending {scripts_dir} to the PATH')
if sys.platform in ['linux', 'darwin']:
with open(bashrc, 'a') as f:
f.write('\n')
f.write('## Added by SimNIBS\n')
f.write(f'SIMNIBS_BIN="{scripts_dir}"\n')
f.write('export PATH=${PATH}:${SIMNIBS_BIN}')
else:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
winreg.SetValueEx(reg,'SIMNIBS_BIN', 0, winreg.REG_SZ, scripts_dir)
path = scripts_dir + ';' + _get_win_path()
winreg.SetValueEx(reg,'Path', 0, winreg.REG_EXPAND_SZ, path)
示例10: set_startup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import KEY_WRITE [as 別名]
def set_startup():
if plexpy.WIN_SYS_TRAY_ICON:
plexpy.WIN_SYS_TRAY_ICON.change_tray_icons()
startup_reg_path = "Software\\Microsoft\\Windows\\CurrentVersion\\Run"
exe = sys.executable
if plexpy.FROZEN:
args = [exe]
else:
args = [exe, plexpy.FULL_PATH]
cmd = ' '.join(cmd_quote(arg) for arg in args).replace('python.exe', 'pythonw.exe').replace("'", '"')
if plexpy.CONFIG.LAUNCH_STARTUP:
try:
winreg.CreateKey(winreg.HKEY_CURRENT_USER, startup_reg_path)
registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_reg_path, 0, winreg.KEY_WRITE)
winreg.SetValueEx(registry_key, common.PRODUCT, 0, winreg.REG_SZ, cmd)
winreg.CloseKey(registry_key)
logger.info("Added Tautulli to Windows system startup registry key.")
return True
except WindowsError as e:
logger.error("Failed to create Windows system startup registry key: %s", e)
return False
else:
# Check if registry value exists
try:
registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, startup_reg_path, 0, winreg.KEY_ALL_ACCESS)
winreg.QueryValueEx(registry_key, common.PRODUCT)
reg_value_exists = True
except WindowsError:
reg_value_exists = False
if reg_value_exists:
try:
winreg.DeleteValue(registry_key, common.PRODUCT)
winreg.CloseKey(registry_key)
logger.info("Removed Tautulli from Windows system startup registry key.")
return True
except WindowsError as e:
logger.error("Failed to delete Windows system startup registry key: %s", e)
return False