Python winreg.SetValueEx() Examples
The following are 30
code examples of winreg.SetValueEx().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
winreg
, or try the search function
.
Example #1
Source File: nzblnkconfig.py From nzb-monkey with MIT License | 7 votes |
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)
Example #2
Source File: win_add2path.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 7 votes |
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
Example #3
Source File: installation.py From blogger-cli with MIT License | 6 votes |
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), )
Example #4
Source File: sysproxy.py From python-proxy with MIT License | 6 votes |
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)
Example #5
Source File: win_add2path.py From odoo13-x64 with GNU General Public License v3.0 | 6 votes |
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
Example #6
Source File: main_window.py From Blender-Version-Manager with GNU General Public License v3.0 | 6 votes |
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)
Example #7
Source File: utils.py From adb with MIT License | 6 votes |
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 #
Example #8
Source File: TaskManager.py From Crypter with GNU General Public License v3.0 | 6 votes |
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)
Example #9
Source File: win_add2path.py From android_universal with MIT License | 6 votes |
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
Example #10
Source File: get-poetry.py From poetry with MIT License | 6 votes |
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), )
Example #11
Source File: get_blogger.py From blogger-cli with MIT License | 6 votes |
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), )
Example #12
Source File: store_env_in_registry.py From coala-quickstart with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #13
Source File: Crypter.py From Crypter with GNU General Public License v3.0 | 5 votes |
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
Example #14
Source File: TaskManager.py From Crypter with GNU General Public License v3.0 | 5 votes |
def disable(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 doesn't exist, create it and set to disabled if not key_exists: reg = winreg.CreateKey(winreg.HKEY_CURRENT_USER, self.DISABLE_KEY_LOCATION) winreg.SetValueEx(reg, "DisableTaskMgr", 0, winreg.REG_DWORD, 0x00000001) winreg.CloseKey(reg) # If enabled, disable it elif key_exists and not 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, 0x00000001) winreg.CloseKey(reg)
Example #15
Source File: store_env_in_registry.py From coala-bears with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #16
Source File: store_env_in_registry.py From coala with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #17
Source File: sysproxy.py From python-proxy with MIT License | 5 votes |
def clear(self): if self.listen is None: return 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 counter = int.from_bytes(value[4:8], 'little') + 1 value = value[:4] + struct.pack('<II', counter, 1) + b'\x00'*44 winreg.SetValueEx(key, self.SUBKEY, None, regtype, value) winreg.CloseKey(key)
Example #18
Source File: set_proxy.py From ahjs5s with GNU General Public License v2.0 | 5 votes |
def set_regkey(name, value): _, reg_type = winreg.QueryValueEx(INTERNET_SETTINGS, name) winreg.SetValueEx(INTERNET_SETTINGS, name, 0, reg_type, value)
Example #19
Source File: install_package.py From r-bridge-install with Apache License 2.0 | 5 votes |
def create_registry_entry(product, arc_version): """Create a registry link back to the arcgisbinding package.""" root_key = winreg.HKEY_CURRENT_USER if product == 'Pro': product_name = "ArcGISPro" else: product_name = "Desktop{}".format(arc_version) reg_path = "SOFTWARE\\Esri\\{}".format(product_name) package_key = 'RintegrationProPackagePath' link_key = None try: full_access = (winreg.KEY_WOW64_64KEY + winreg.KEY_ALL_ACCESS) # find the key, 64- or 32-bit we want it all link_key = winreg.OpenKey(root_key, reg_path, 0, full_access) except fnf_exception as error: handle_fnf(error) if link_key: try: arcpy.AddMessage("Using registry key to link install.") binding_path = "{}\\{}".format(r_lib_path(), "arcgisbinding") winreg.SetValueEx(link_key, package_key, 0, winreg.REG_SZ, binding_path) except fnf_exception as error: handle_fnf(error)
Example #20
Source File: ext_server_uacamola.py From uac-a-mola with GNU General Public License v3.0 | 5 votes |
def create_value(self, key, value_name, value): """ Creates a value THAT DOESN'T EXIST, we need to keep track of the keys that we are creating """ self.no_restore = False try: return winreg.SetValueEx(key, value_name, 0, winreg.REG_SZ, value) except WindowsError as error: self.no_restore = True return None
Example #21
Source File: recipe-577621.py From code with MIT License | 5 votes |
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)
Example #22
Source File: _registry.py From pipenv with MIT License | 5 votes |
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)))
Example #23
Source File: _registry.py From pipenv with MIT License | 5 votes |
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)))
Example #24
Source File: _registry.py From pythonfinder with MIT License | 5 votes |
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)))
Example #25
Source File: _registry.py From pythonfinder with MIT License | 5 votes |
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)))
Example #26
Source File: Windows.py From keyrings.alt with MIT License | 5 votes |
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)
Example #27
Source File: px.py From px with MIT License | 5 votes |
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()
Example #28
Source File: regobj.py From NVDARemote with GNU General Public License v2.0 | 5 votes |
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)
Example #29
Source File: postinstall_simnibs.py From simnibs with GNU General Public License v3.0 | 5 votes |
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)
Example #30
Source File: util.py From pympress with GNU General Public License v2.0 | 4 votes |
def set_screensaver(must_disable, window): """ Enable or disable the screensaver. Args: must_disable (`bool`): if `True`, indicates that the screensaver must be disabled; otherwise it will be enabled window (:class:`~Gdk.Window`): The window on the screen where the screensaver is to be suspended. """ if IS_MAC_OS: # On Mac OS X we can use caffeinate to prevent the display from sleeping if must_disable: if set_screensaver.dpms_was_enabled is None or set_screensaver.dpms_was_enabled.poll(): set_screensaver.dpms_was_enabled = subprocess.Popen(['caffeinate', '-d', '-w', str(os.getpid())]) else: if set_screensaver.dpms_was_enabled and not set_screensaver.dpms_was_enabled.poll(): set_screensaver.dpms_was_enabled.kill() set_screensaver.dpms_was_enabled.poll() set_screensaver.dpms_was_enabled = None elif IS_POSIX: # Import here because util should be imported without depending on gi from gi.repository import Gio # On Linux and Wayland we can use a dbus interface to tell the screensaver # to not lock the screen, should work on all freedesktop compliant desktops # eg. Gnome, KDE,... bus = Gio.bus_get_sync(Gio.BusType.SESSION, None) iface = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None, 'org.freedesktop.ScreenSaver', '/org/freedesktop/ScreenSaver', 'org.freedesktop.ScreenSaver', None) if must_disable and not set_screensaver.dpms_was_enabled: set_screensaver.dbus_cookie = iface.Inhibit("(ss)", "pympress", _("Fullscreen Presentation running")) set_screensaver.dpms_was_enabled = True if not must_disable and set_screensaver.dpms_was_enabled: iface.UnInhibit("(u)", set_screensaver.dbus_cookie) set_screensaver.dbus_cookie = None set_screensaver.dpms_was_enabled = False elif IS_WINDOWS: try: with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Control Panel\Desktop', 0, winreg.KEY_QUERY_VALUE | winreg.KEY_SET_VALUE) as key: if must_disable: value, regtype = winreg.QueryValueEx(key, "ScreenSaveActive") assert(regtype == winreg.REG_SZ) set_screensaver.dpms_was_enabled = (value == "1") if set_screensaver.dpms_was_enabled: winreg.SetValueEx(key, "ScreenSaveActive", 0, winreg.REG_SZ, "0") elif set_screensaver.dpms_was_enabled: winreg.SetValueEx(key, "ScreenSaveActive", 0, winreg.REG_SZ, "1") except (OSError, PermissionError): logger.exception(_("access denied when trying to access screen saver settings in registry!")) else: logger.warning(_("Unsupported OS: can't enable/disable screensaver")) #: remember DPMS setting before we change it