本文整理匯總了Python中winreg.SetValueEx方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.SetValueEx方法的具體用法?Python winreg.SetValueEx怎麽用?Python winreg.SetValueEx使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類winreg
的用法示例。
在下文中一共展示了winreg.SetValueEx方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: config_win
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def config_win():
try:
import winreg as reg
key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk')
reg.SetValue(key, '', reg.REG_SZ, 'URL:nzblnk')
reg.SetValueEx(key, 'URL Protocol', 0, reg.REG_SZ, '')
reg.CloseKey(key)
key = reg.CreateKey(reg.HKEY_CURRENT_USER, 'SOFTWARE\\Classes\\nzblnk\\shell\\open\\command')
reg.SetValue(key, '', reg.REG_SZ, '"{0}" "%1"'.format(op.normpath(os.path.abspath(sys.executable))))
reg.CloseKey(key)
except (OSError, ImportError):
print(Col.FAIL + ' FAILED to setup registry link for NZBLNK scheme!' + Col.OFF)
sleep(wait_time)
sys.exit(2)
示例2: set_windows_path_var
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def set_windows_path_var(self, value):
import ctypes
with winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) as root:
with winreg.OpenKey(root, "Environment", 0, winreg.KEY_ALL_ACCESS) as key:
winreg.SetValueEx(key, "PATH", 0, winreg.REG_EXPAND_SZ, value)
# Tell other processes to update their environment
HWND_BROADCAST = 0xFFFF
WM_SETTINGCHANGE = 0x1A
SMTO_ABORTIFHUNG = 0x0002
result = ctypes.c_long()
SendMessageTimeoutW = ctypes.windll.user32.SendMessageTimeoutW
SendMessageTimeoutW(
HWND_BROADCAST,
WM_SETTINGCHANGE,
0,
u"Environment",
SMTO_ABORTIFHUNG,
5000,
ctypes.byref(result),
)
示例3: toggle_run_on_startup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def toggle_run_on_startup(self, is_checked):
if (self.platform == 'Windows'):
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
r'SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run',
0, winreg.KEY_SET_VALUE)
if (is_checked):
path = sys.executable
winreg.SetValueEx(key, 'Blender Version Manager',
0, winreg.REG_SZ, path)
else:
try:
winreg.DeleteValue(key, 'Blender Version Manager')
except:
pass
key.Close()
self.settings.setValue('is_run_on_startup', is_checked)
示例4: modify
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def modify():
pythonpath = os.path.dirname(os.path.normpath(sys.executable))
scripts = os.path.join(pythonpath, "Scripts")
appdata = os.environ["APPDATA"]
if hasattr(site, "USER_SITE"):
usersite = site.USER_SITE.replace(appdata, "%APPDATA%")
userpath = os.path.dirname(usersite)
userscripts = os.path.join(userpath, "Scripts")
else:
userscripts = None
with winreg.CreateKey(HKCU, ENV) as key:
try:
envpath = winreg.QueryValueEx(key, PATH)[0]
except OSError:
envpath = DEFAULT
paths = [envpath]
for path in (pythonpath, scripts, userscripts):
if path and path not in envpath and os.path.isdir(path):
paths.append(path)
envpath = os.pathsep.join(paths)
winreg.SetValueEx(key, PATH, 0, winreg.REG_EXPAND_SZ, envpath)
return paths, envpath
示例5: __init__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def __init__(self, args):
self.listen = None
for option in args.listen:
protos = [x.name for x in option.protos]
if option.unix or 'ssl' in protos or 'secure' in protos:
continue
if 'http' in protos:
self.listen = option
break
if self.listen is None:
print('No server listen on localhost by http')
import winreg
key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, self.KEY, 0, winreg.KEY_ALL_ACCESS)
value, regtype = winreg.QueryValueEx(key, self.SUBKEY)
assert regtype == winreg.REG_BINARY
server = f'localhost:{self.listen.port}'.encode()
bypass = '<local>'.encode()
counter = int.from_bytes(value[4:8], 'little') + 1
value = value[:4] + struct.pack('<III', counter, 3, len(server)) + server + struct.pack('<I', len(bypass)) + bypass + b'\x00'*36
winreg.SetValueEx(key, self.SUBKEY, None, regtype, value)
winreg.CloseKey(key)
示例6: set_doc_author_keys
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def set_doc_author_keys(userinitials, username):
try:
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\Microsoft\Office\Common\UserInfo', 0,
winreg.KEY_ALL_ACCESS) as key:
winreg.SetValueEx(key, "UserName", 0, winreg.REG_SZ, username)
winreg.SetValueEx(key, "UserInitials", 0, winreg.REG_SZ, userinitials)
except FileNotFoundError:
print("[!] Office may not be installed and initially run to create the necessary key locations. "
"Please install and open Office once to set it up.")
raise FileNotFoundError
# returns the list of playbook items to allow for the creation of the file, and if necessary, renaming it to the
# desired extension
#
# set_save_format determines the file format
# set_save_extension will be the extension compatible with the type of file you're saving.
# docm format can't be named .doc when saved by word, but it will work if renamed afterward
#
# set_extension_after_save will indicate the file needs renamed after it is saved
#
示例7: enable
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def enable(self):
'''
@summary: Disables Windows Task Manager
'''
key_exists = False
# Try to read the key
try:
reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION)
disabled = winreg.QueryValueEx(reg, "DisableTaskMgr")[0]
winreg.CloseKey(reg)
key_exists = True
except:
pass
# If key exists and is disabled, enable it
if key_exists and disabled:
reg = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
self.DISABLE_KEY_LOCATION,
0,
winreg.KEY_SET_VALUE)
winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000000)
winreg.CloseKey(reg)
示例8: path_cleanup
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [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)
示例9: set_envvar_in_registry
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def set_envvar_in_registry(envvar, value):
try:
import winreg
except ImportError:
import _winreg as winreg
reg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
with winreg.OpenKey(reg, KEY, 0, winreg.KEY_ALL_ACCESS) as regkey:
winreg.SetValueEx(regkey, envvar, 0, winreg.REG_EXPAND_SZ, value)
示例10: __setitem__
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def __setitem__(self,name,value):
"""Item assignment sets key values."""
self.sam |= KEY_SET_VALUE
if not isinstance(value,Value):
value = Value(value,name)
_winreg.SetValueEx(self.hkey,name,0,value.type,value.data)
示例11: install
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [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()
示例12: set_password
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def set_password(self, service, username, password):
"""Write the password to the registry
"""
# encrypt the password
password_encrypted = _win_crypto.encrypt(password.encode('utf-8'))
# encode with base64
password_base64 = base64.encodestring(password_encrypted)
# encode again to unicode
password_saved = password_base64.decode('ascii')
# store the password
key_name = self._key_for_service(service)
hkey = winreg.CreateKey(winreg.HKEY_CURRENT_USER, key_name)
winreg.SetValueEx(hkey, username, 0, winreg.REG_SZ, password_saved)
示例13: set_value
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [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)))
示例14: _set_all_values
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [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)))
示例15: setenv
# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import SetValueEx [as 別名]
def setenv(self, name, value):
# Note: for 'system' scope, you must run this as Administrator
key = winreg.OpenKey(self.root, self.subkey, 0, winreg.KEY_ALL_ACCESS)
winreg.SetValueEx(key, name, 0, winreg.REG_EXPAND_SZ, value)
winreg.CloseKey(key)
# For some strange reason, calling SendMessage from the current process
# doesn't propagate environment changes at all.
# TODO: handle CalledProcessError (for assert)
check_call('''\
"%s" -c "import win32api, win32con; assert win32api.SendMessage(win32con.HWND_BROADCAST, win32con.WM_SETTINGCHANGE, 0, 'Environment')"''' % sys.executable)