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: win_add2path.py From oss-ftp with MIT 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"): userpath = site.USER_SITE.replace(appdata, "%APPDATA%") userscripts = os.path.join(userpath, "Scripts") else: userscripts = None with _winreg.CreateKey(HKCU, ENV) as key: try: envpath = _winreg.QueryValueEx(key, PATH)[0] except WindowsError: 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 #2
Source File: util.py From byob with GNU General Public License v3.0 | 6 votes |
def registry_key(key, subkey, value): """ Create a new Windows Registry Key in HKEY_CURRENT_USER `Required` :param str key: primary registry key name :param str subkey: registry key sub-key name :param str value: registry key sub-key value Returns True if successful, otherwise False """ try: import _winreg reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value) _winreg.CloseKey(reg_key) return True except Exception as e: log(e) return False
Example #3
Source File: shell_view.py From ironpython2 with Apache License 2.0 | 6 votes |
def DllRegisterServer(): import _winreg key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \ "Explorer\\Desktop\\Namespace\\" + \ ShellFolderRoot._reg_clsid_) _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellFolderRoot._reg_desc_) # And special shell keys under our CLSID key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "CLSID\\" + ShellFolderRoot._reg_clsid_ + "\\ShellFolder") # 'Attributes' is an int stored as a binary! use struct attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \ shellcon.SFGAO_BROWSABLE import struct s = struct.pack("i", attr) _winreg.SetValueEx(key, "Attributes", 0, _winreg.REG_BINARY, s) print ShellFolderRoot._reg_desc_, "registration complete."
Example #4
Source File: shell_view.py From Email_My_PC with MIT License | 6 votes |
def DllRegisterServer(): import _winreg key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\" \ "Explorer\\Desktop\\Namespace\\" + \ ShellFolderRoot._reg_clsid_) _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ShellFolderRoot._reg_desc_) # And special shell keys under our CLSID key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "CLSID\\" + ShellFolderRoot._reg_clsid_ + "\\ShellFolder") # 'Attributes' is an int stored as a binary! use struct attr = shellcon.SFGAO_FOLDER | shellcon.SFGAO_HASSUBFOLDER | \ shellcon.SFGAO_BROWSABLE import struct s = struct.pack("i", attr) _winreg.SetValueEx(key, "Attributes", 0, _winreg.REG_BINARY, s) print ShellFolderRoot._reg_desc_, "registration complete."
Example #5
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 #6
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 #7
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 #8
Source File: iebutton.py From ironpython2 with Apache License 2.0 | 6 votes |
def register(classobj): import _winreg subKeyCLSID = "SOFTWARE\\Microsoft\\Internet Explorer\\Extensions\\%38s" % classobj._reg_clsid_ try: hKey = _winreg.CreateKey( _winreg.HKEY_LOCAL_MACHINE, subKeyCLSID ) subKey = _winreg.SetValueEx( hKey, "ButtonText", 0, _winreg.REG_SZ, classobj._button_text_ ) _winreg.SetValueEx( hKey, "ClsidExtension", 0, _winreg.REG_SZ, classobj._reg_clsid_ ) # reg value for calling COM object _winreg.SetValueEx( hKey, "CLSID", 0, _winreg.REG_SZ, "{1FBA04EE-3024-11D2-8F1F-0000F87ABD16}" ) # CLSID for button that sends command to COM object _winreg.SetValueEx( hKey, "Default Visible", 0, _winreg.REG_SZ, "Yes" ) _winreg.SetValueEx( hKey, "ToolTip", 0, _winreg.REG_SZ, classobj._tool_tip_ ) _winreg.SetValueEx( hKey, "Icon", 0, _winreg.REG_SZ, classobj._icon_) _winreg.SetValueEx( hKey, "HotIcon", 0, _winreg.REG_SZ, classobj._hot_icon_) except WindowsError: print "Couldn't set standard toolbar reg keys." else: print "Set standard toolbar reg keys."
Example #9
Source File: win_add2path.py From Carnets with BSD 3-Clause "New" or "Revised" 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"): userpath = site.USER_SITE.replace(appdata, "%APPDATA%") userscripts = os.path.join(userpath, "Scripts") else: userscripts = None with _winreg.CreateKey(HKCU, ENV) as key: try: envpath = _winreg.QueryValueEx(key, PATH)[0] except WindowsError: 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: Install.py From EventGhost with GNU General Public License v2.0 | 6 votes |
def Install(): AddOrRemoveHIDKeys(True) osExtension = "x86" if Is64BitOS(): osExtension = "x64" pluginDir = dirname(__file__.decode(sys.getfilesystemencoding())) tmpExe = join(pluginDir, "AlternateMceIrService_%s.exe"%osExtension) myExe = join(pluginDir, "AlternateMceIrService.exe") try: os.remove(myExe) except: pass shutil.copyfile(tmpExe,myExe) key = reg.CreateKey(reg.HKEY_LOCAL_MACHINE, ServiceKey+"\\AlternateMceIrService") reg.SetValueEx(key, "EventMessageFile", 0, reg.REG_SZ, myExe) reg.SetValueEx(key, "TypesSupported", 0, reg.REG_DWORD, 7) service = Service(u"AlternateMceIrService") service.Install(myExe) service.Start() print "Service successfully installed"
Example #11
Source File: winregistry.py From cross3d with MIT License | 6 votes |
def listRegKeyValues(registry, key, architecture=None): """ Returns a list of child keys and their values as tuples. Each tuple contains 3 items. - A string that identifies the value name - An object that holds the value data, and whose type depends on the underlying registry type - An integer that identifies the type of the value data (see table in docs for _winreg.SetValueEx) Args: registry (str): The registry to look in. 'HKEY_LOCAL_MACHINE' for example key (str): The key to open. r'Software\Autodesk\Softimage\InstallPaths' for example architecture (int | None): 32 or 64 bit. If None use system default. Defaults to None Returns: List of tuples """ import _winreg regKey = getRegKey(registry, key, architecture=architecture) ret = [] if regKey: subKeys, valueCount, modified = _winreg.QueryInfoKey(regKey) for index in range(valueCount): ret.append(_winreg.EnumValue(regKey, index)) return ret
Example #12
Source File: RegistryStorageProvider.py From AltFS with BSD 3-Clause "New" or "Revised" License | 6 votes |
def write_block(self, bucket_id, value_id, data=""): """Described in parent class""" try: value_name = self._get_value_name( bucket_id, value_id) except BucketValueMissingException: logger.debug( "value with id does not exist in specified bucket." + " generating a new value name for bucket id %s" % bucket_id) value_name = self._generate_value_name(bucket_id) logger.debug("generated a new value name in bucket id %s: %s" % ( bucket_id, value_name)) with self._get_bucket_key(bucket_id, _winreg.KEY_WRITE) as key: _winreg.SetValueEx(key, value_name, 0, _winreg.REG_BINARY, data) return RegistryStorageProvider.value_name_to_value_id(value_name)
Example #13
Source File: textext.py From inkscapeMadeEasy with GNU General Public License v3.0 | 6 votes |
def save(self): if USE_WINDOWS: import _winreg try: key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, self.keyname, sam=_winreg.KEY_SET_VALUE | _winreg.KEY_WRITE) except: key = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, self.keyname) try: for k, v in self.values.iteritems(): _winreg.SetValueEx(key, str(k), 0, _winreg.REG_SZ, str(v)) finally: key.Close() else: d = os.path.dirname(self.filename) if not os.path.isdir(d): os.makedirs(d) f = open(self.filename, 'w') try: data = '\n'.join(["%s=%s" % (k,v) for k,v in self.values.iteritems()]) f.write(data) finally: f.close()
Example #14
Source File: platform.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
def enforce_shortcut(config, log_func): if os.name != 'nt': return path = win32api.GetModuleFileName(0) if 'python' in path.lower(): # oops, running the .py too lazy to make that work path = r"C:\Program Files\BitTorrent\bittorrent.exe" root_key = _winreg.HKEY_CURRENT_USER subkey = r'Software\Microsoft\Windows\CurrentVersion\run' key = _winreg.CreateKey(root_key, subkey) if config['launch_on_startup']: _winreg.SetValueEx(key, app_name, 0, _winreg.REG_SZ, '"%s" --force_start_minimized' % path) else: try: _winreg.DeleteValue(key, app_name) except WindowsError, e: # value doesn't exist pass
Example #15
Source File: win_add2path.py From datafari with Apache License 2.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"): userpath = site.USER_SITE.replace(appdata, "%APPDATA%") userscripts = os.path.join(userpath, "Scripts") else: userscripts = None with _winreg.CreateKey(HKCU, ENV) as key: try: envpath = _winreg.QueryValueEx(key, PATH)[0] except WindowsError: 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 #16
Source File: util.py From byob with GNU General Public License v3.0 | 6 votes |
def registry_key(key, subkey, value): """ Create a new Windows Registry Key in HKEY_CURRENT_USER `Required` :param str key: primary registry key name :param str subkey: registry key sub-key name :param str value: registry key sub-key value Returns True if successful, otherwise False """ try: import _winreg reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value) _winreg.CloseKey(reg_key) return True except Exception as e: log(e) return False
Example #17
Source File: util.py From byob with GNU General Public License v3.0 | 6 votes |
def registry_key(key, subkey, value): """ Create a new Windows Registry Key in HKEY_CURRENT_USER `Required` :param str key: primary registry key name :param str subkey: registry key sub-key name :param str value: registry key sub-key value Returns True if successful, otherwise False """ try: import _winreg reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value) _winreg.CloseKey(reg_key) return True except Exception as e: log(e) return False
Example #18
Source File: util.py From byob with GNU General Public License v3.0 | 6 votes |
def registry_key(key, subkey, value): """ Create a new Windows Registry Key in HKEY_CURRENT_USER `Required` :param str key: primary registry key name :param str subkey: registry key sub-key name :param str value: registry key sub-key value Returns True if successful, otherwise False """ try: import _winreg reg_key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER, key, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(reg_key, subkey, 0, _winreg.REG_SZ, value) _winreg.CloseKey(reg_key) return True except Exception as e: log(e) return False
Example #19
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 #20
Source File: empty_volume_cache.py From Email_My_PC with MIT License | 5 votes |
def DllRegisterServer(): # Also need to register specially in: # HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches # See link at top of file. import _winreg kn = r"Software\Microsoft\Windows\CurrentVersion\Explorer\VolumeCaches\%s" \ % (EmptyVolumeCache._reg_desc_,) key = _winreg.CreateKey(_winreg.HKEY_LOCAL_MACHINE, kn) _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, EmptyVolumeCache._reg_clsid_)
Example #21
Source File: Install.py From EventGhost with GNU General Public License v2.0 | 5 votes |
def AddOrRemoveHIDKeys(isInstall): HID_SUB_KEY = "SYSTEM\\CurrentControlSet\\Services\\HidIr\\Remotes\\745a17a0-74d3-11d0-b6fe-00a0c90f57d" ValuesToCheck = ['a','b'] for a in ValuesToCheck: tmpkey = HID_SUB_KEY+a try: key = reg.OpenKey(reg.HKEY_LOCAL_MACHINE, tmpkey, 0, reg.KEY_ALL_ACCESS) for i in xrange(4): valueName = 'CodeSetNum%i' % i if isInstall: reg.DeleteValue(key, valueName) else: reg.SetValueEx(key, valueName, 0, reg.REG_DWORD, i + 1) except WindowsError: continue
Example #22
Source File: __init__.py From butterflow with MIT License | 5 votes |
def add_registry_keys(): for key in get_local_machine_registry_subkeys(KHRONOS_REG_PATH): if key is not None: key = RegistryKey(key[0], key[2], key[1]) if key in KEYS_NEEDED: KEYS_NEEDED.remove(key) else: # print("?: "+str(key)) pass # print("No keys left\nKeys to add: "+str(KEYS_NEEDED)) for key_needed in KEYS_NEEDED: try: try: subkey = winreg.CreateKeyEx(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_CREATE_SUB_KEY) except WindowsError as error: print("Couldn't create subkeys at: %s\tReason: %s" % (KHRONOS_REG_PATH, error)) exit(1) finally: subkey.Close() with winreg.OpenKey(REG_HIVE, KHRONOS_REG_PATH, 0, winreg.KEY_WRITE) as key: winreg.SetValueEx(key, key_needed.name, 0, key_needed.data_type, key_needed.value) # print("+"+str(key_needed)) except WindowsError as error: print("Couldn't create (%s)\tReason: %s" % (key_needed, error)) exit(1) # TODO: How to Enumerate Vendor ICDs on Windows: https://github.com/KhronosGroup/OpenCL-Docs/blob/master/ext/cl_khr_icd.txt#L68 # SEARCH_HIVE=winreg.HKEY_LOCAL_MACHINE
Example #23
Source File: column_provider.py From Email_My_PC with MIT License | 5 votes |
def DllRegisterServer(): import _winreg # Special ColumnProvider key key = _winreg.CreateKey(_winreg.HKEY_CLASSES_ROOT, "Folder\\ShellEx\\ColumnHandlers\\" + \ str(ColumnProvider._reg_clsid_ )) _winreg.SetValueEx(key, None, 0, _winreg.REG_SZ, ColumnProvider._reg_desc_) print ColumnProvider._reg_desc_, "registration complete."
Example #24
Source File: autorun.py From TinkererShell with GNU General Public License v3.0 | 5 votes |
def add(name, application): """add a new autostart entry""" key = get_runonce() _winreg.SetValueEx(key, name, 0, _winreg.REG_SZ, application) _winreg.CloseKey(key)
Example #25
Source File: persistence.py From Intensio-Obfuscator with MIT License | 5 votes |
def windows_persistence(): import _winreg from _winreg import HKEY_CURRENT_USER as HKCU run_key = r'Software\Microsoft\Windows\CurrentVersion\Run' bin_path = sys.executable try: reg_key = _winreg.OpenKey(HKCU, run_key, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(reg_key, 'br', 0, _winreg.REG_SZ, bin_path) _winreg.CloseKey(reg_key) return True, 'HKCU Run registry key applied' except WindowsError: return False, 'HKCU Run registry key failed'
Example #26
Source File: persistence.py From Intensio-Obfuscator with MIT License | 5 votes |
def windows_persistence(): import _winreg from _winreg import HKEY_CURRENT_USER as HKCU run_key = r'Software\Microsoft\Windows\CurrentVersion\Run' bin_path = sys.executable try: reg_key = _winreg.OpenKey(HKCU, run_key, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(reg_key, 'br', 0, _winreg.REG_SZ, bin_path) _winreg.CloseKey(reg_key) return True, 'HKCU Run registry key applied' except WindowsError: return False, 'HKCU Run registry key failed'
Example #27
Source File: persistence.py From Intensio-Obfuscator with MIT License | 5 votes |
def srOXhtoTWVPOQTAFQsEjXglmECQYMydH(): import _winreg from _winreg import HKEY_CURRENT_USER as HKCU ejhEOFlPViXKPUHKJhcSyqqQjSUcagli = r'Software\Microsoft\Windows\CurrentVersion\Run' MtcFrCNqZIqaQyIxdGTfhTosybVfegHt = sys.executable try: SCyNiWCgkJlizIsydlByszPSbHjrsmmo = _winreg.OpenKey(HKCU, ejhEOFlPViXKPUHKJhcSyqqQjSUcagli, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(SCyNiWCgkJlizIsydlByszPSbHjrsmmo, 'br', 0, _winreg.REG_SZ, MtcFrCNqZIqaQyIxdGTfhTosybVfegHt) _winreg.CloseKey(SCyNiWCgkJlizIsydlByszPSbHjrsmmo) return True, 'HKCU Run registry key applied' except WindowsError: return False, 'HKCU Run registry key failed'
Example #28
Source File: persistence.py From Intensio-Obfuscator with MIT License | 5 votes |
def windows_persistence(): import _winreg from _winreg import HKEY_CURRENT_USER as HKCU run_key = r'Software\Microsoft\Windows\CurrentVersion\Run' bin_path = sys.executable try: reg_key = _winreg.OpenKey(HKCU, run_key, 0, _winreg.KEY_WRITE) _winreg.SetValueEx(reg_key, 'br', 0, _winreg.REG_SZ, bin_path) _winreg.CloseKey(reg_key) return True, 'HKCU Run registry key applied' except WindowsError: return False, 'HKCU Run registry key failed'
Example #29
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 #30
Source File: platform.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def write_language_file(lang): """Writes the language file. The language file contains the name of the selected language, not any translations.""" if lang != '': # system default get_language(lang) if os.name == 'nt': regko = _winreg.CreateKey(_winreg.HKEY_CURRENT_USER, "Software\\BitTorrent") if lang == '': _winreg.DeleteValue(regko, "Language") else: lcid = None # I want two-way dicts for id, code in language.locale_sucks.iteritems(): if code.lower() == lang.lower(): lcid = id break if not lcid: raise KeyError(lang) _winreg.SetValueEx(regko, "Language", 0, _winreg.REG_SZ, str(lcid)) else: lang_file_name = language_path() lang_file = open(lang_file_name, 'w') lang_file.write(lang) lang_file.close()