Python winreg.REG_SZ Examples

The following are 30 code examples of winreg.REG_SZ(). 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 vote down vote up
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: __init__.py    From browser_cookie3 with GNU Lesser General Public License v3.0 7 votes vote down vote up
def windows_group_policy_path():
    # we know that we're running under windows at this point so it's safe to do these imports
    from winreg import ConnectRegistry, HKEY_LOCAL_MACHINE, OpenKeyEx, QueryValueEx, REG_EXPAND_SZ, REG_SZ
    try:
        root = ConnectRegistry(None, HKEY_LOCAL_MACHINE)
        policy_key = OpenKeyEx(root, r"SOFTWARE\Policies\Google\Chrome")
        user_data_dir, type_ = QueryValueEx(policy_key, "UserDataDir")
        if type_ == REG_EXPAND_SZ:
            user_data_dir = os.path.expandvars(user_data_dir)
        elif type_ != REG_SZ:
            return None
    except OSError:
        return None
    return os.path.join(user_data_dir, "Default", "Cookies")


# Code adapted slightly from https://github.com/Arnie97/chrome-cookies 
Example #3
Source File: local_client.py    From galaxy_blizzard_plugin with MIT License 6 votes vote down vote up
def __search_registry_for_run_cmd(self, *args):
        """
        :param args - arguments as for winreg.OpenKey()
        :returns value of the first string-type key or False if given registry does not exists
        """
        try:
            key = winreg.OpenKey(*args)
            for i in range(1024):
                try:
                    _, exe_cmd, _type = winreg.EnumValue(key, i)
                    if exe_cmd and _type == winreg.REG_SZ:  # null-terminated string
                        return exe_cmd
                except OSError:  # no more data
                    break
        except FileNotFoundError:
            return None 
Example #4
Source File: utils.py    From adb with MIT License 6 votes vote down vote up
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 #5
Source File: main_window.py    From Blender-Version-Manager with GNU General Public License v3.0 6 votes vote down vote up
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 #6
Source File: Crypter.py    From Crypter with GNU General Public License v3.0 6 votes vote down vote up
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 #7
Source File: install_package.py    From r-bridge-install with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: _msvccompiler.py    From Imogen with MIT License 5 votes vote down vote up
def _find_vc2015():
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    best_version = 0
    best_dir = None
    with key:
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
    return best_version, best_dir 
Example #9
Source File: mimetypes.py    From android_universal with MIT License 5 votes vote down vote up
def read_windows_registry(self, strict=True):
        """
        Load the MIME types database from Windows registry.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.
        """

        # Windows only
        if not _winreg:
            return

        def enum_types(mimedb):
            i = 0
            while True:
                try:
                    ctype = _winreg.EnumKey(mimedb, i)
                except OSError:
                    break
                else:
                    if '\0' not in ctype:
                        yield ctype
                i += 1

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises OSError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except OSError:
                    continue 
Example #10
Source File: mimetypes.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def read_windows_registry(self, strict=True):
        """
        Load the MIME types database from Windows registry.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.
        """

        # Windows only
        if not _winreg:
            return

        def enum_types(mimedb):
            i = 0
            while True:
                try:
                    ctype = _winreg.EnumKey(mimedb, i)
                except EnvironmentError:
                    break
                else:
                    if '\0' not in ctype:
                        yield ctype
                i += 1

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises EnvironmentError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except EnvironmentError:
                    continue 
Example #11
Source File: registry.py    From BoomER with GNU General Public License v3.0 5 votes vote down vote up
def set_value(self):
        try:
            k = winreg.SetValue(self.key, self.subkey, winreg.REG_SZ, self.value)
            to_return = self._return_success(self.current_key)
        except WindowsError as e:
            to_return = self._return_error(str(e))
        return to_return 
Example #12
Source File: ext_server_uacamola.py    From uac-a-mola with GNU General Public License v3.0 5 votes vote down vote up
def set_value(self, key, subkey, value):
        """ Set a value in a custom subkey
        """
        try:
            return winreg.SetValue(key, subkey, winreg.REG_SZ, value)
        except:
            self.no_restore = True
            return None 
Example #13
Source File: ext_server_uacamola.py    From uac-a-mola with GNU General Public License v3.0 5 votes vote down vote up
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 #14
Source File: mimetypes.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def read_windows_registry(self, strict=True):
        """
        Load the MIME types database from Windows registry.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.
        """

        # Windows only
        if not _winreg:
            return

        def enum_types(mimedb):
            i = 0
            while True:
                try:
                    ctype = _winreg.EnumKey(mimedb, i)
                except EnvironmentError:
                    break
                else:
                    if '\0' not in ctype:
                        yield ctype
                i += 1

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises EnvironmentError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except EnvironmentError:
                    continue 
Example #15
Source File: Crypter.py    From Crypter with GNU General Public License v3.0 5 votes vote down vote up
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 #16
Source File: _msvccompiler.py    From setuptools with MIT License 5 votes vote down vote up
def _find_vc2015():
    try:
        key = winreg.OpenKeyEx(
            winreg.HKEY_LOCAL_MACHINE,
            r"Software\Microsoft\VisualStudio\SxS\VC7",
            access=winreg.KEY_READ | winreg.KEY_WOW64_32KEY
        )
    except OSError:
        log.debug("Visual C++ is not registered")
        return None, None

    best_version = 0
    best_dir = None
    with key:
        for i in count():
            try:
                v, vc_dir, vt = winreg.EnumValue(key, i)
            except OSError:
                break
            if v and vt == winreg.REG_SZ and os.path.isdir(vc_dir):
                try:
                    version = int(float(v))
                except (ValueError, TypeError):
                    continue
                if version >= 14 and version > best_version:
                    best_version, best_dir = version, vc_dir
    return best_version, best_dir 
Example #17
Source File: mimetypes.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def read_windows_registry(self, strict=True):
        """
        Load the MIME types database from Windows registry.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.
        """

        # Windows only
        if not _winreg:
            return

        def enum_types(mimedb):
            i = 0
            while True:
                try:
                    ctype = _winreg.EnumKey(mimedb, i)
                except EnvironmentError:
                    break
                else:
                    if '\0' not in ctype:
                        yield ctype
                i += 1

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises EnvironmentError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except EnvironmentError:
                    continue 
Example #18
Source File: mimetypes.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def read_windows_registry(self, strict=True):
        """
        Load the MIME types database from Windows registry.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.
        """

        # Windows only
        if not _winreg:
            return

        def enum_types(mimedb):
            i = 0
            while True:
                try:
                    ctype = _winreg.EnumKey(mimedb, i)
                except OSError:
                    break
                else:
                    if '\0' not in ctype:
                        yield ctype
                i += 1

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises OSError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except OSError:
                    continue 
Example #19
Source File: _winconsole.py    From vistir with ISC License 5 votes vote down vote up
def get_value_from_tuple(value, value_type):
    try:
        import winreg
    except ImportError:
        import _winreg as winreg
    if value_type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ):
        if "\0" in value:
            return value[: value.index("\0")]
        return value
    return None 
Example #20
Source File: mimetypes.py    From Imogen with MIT License 5 votes vote down vote up
def read_windows_registry(self, strict=True):
        """
        Load the MIME types database from Windows registry.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.
        """

        # Windows only
        if not _winreg:
            return

        def enum_types(mimedb):
            i = 0
            while True:
                try:
                    ctype = _winreg.EnumKey(mimedb, i)
                except OSError:
                    break
                else:
                    if '\0' not in ctype:
                        yield ctype
                i += 1

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises OSError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except OSError:
                    continue 
Example #21
Source File: mimetypes.py    From odoo13-x64 with GNU General Public License v3.0 5 votes vote down vote up
def read_windows_registry(self, strict=True):
        """
        Load the MIME types database from Windows registry.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.
        """

        # Windows only
        if not _winreg:
            return

        def enum_types(mimedb):
            i = 0
            while True:
                try:
                    ctype = _winreg.EnumKey(mimedb, i)
                except OSError:
                    break
                else:
                    if '\0' not in ctype:
                        yield ctype
                i += 1

        with _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, '') as hkcr:
            for subkeyname in enum_types(hkcr):
                try:
                    with _winreg.OpenKey(hkcr, subkeyname) as subkey:
                        # Only check file extensions
                        if not subkeyname.startswith("."):
                            continue
                        # raises OSError if no 'Content Type' value
                        mimetype, datatype = _winreg.QueryValueEx(
                            subkey, 'Content Type')
                        if datatype != _winreg.REG_SZ:
                            continue
                        self.add_type(mimetype, subkeyname, strict)
                except OSError:
                    continue 
Example #22
Source File: platform.py    From brotab with MIT License 5 votes vote down vote up
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 #23
Source File: _winconsole.py    From pipenv with MIT License 5 votes vote down vote up
def get_value_from_tuple(value, value_type):
    try:
        import winreg
    except ImportError:
        import _winreg as winreg
    if value_type in (winreg.REG_SZ, winreg.REG_EXPAND_SZ):
        if "\0" in value:
            return value[: value.index("\0")]
        return value
    return None 
Example #24
Source File: _registry.py    From pipenv with MIT License 5 votes vote down vote up
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 pipenv with MIT License 5 votes vote down vote up
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: _registry.py    From pipenv with MIT License 5 votes vote down vote up
def get_value_from_tuple(value, vtype):
    if vtype == winreg.REG_SZ:
        if '\0' in value:
            return value[:value.index('\0')]
        return value
    return None 
Example #27
Source File: _registry.py    From pythonfinder with MIT License 5 votes vote down vote up
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 #28
Source File: _registry.py    From pythonfinder with MIT License 5 votes vote down vote up
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 #29
Source File: _registry.py    From pythonfinder with MIT License 5 votes vote down vote up
def get_value_from_tuple(value, vtype):
    if vtype == winreg.REG_SZ:
        if '\0' in value:
            return value[:value.index('\0')]
        return value
    return None 
Example #30
Source File: Windows.py    From keyrings.alt with MIT License 5 votes vote down vote up
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)