Python winreg.EnumValue() Examples

The following are 30 code examples of winreg.EnumValue(). 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: 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 #2
Source File: get_applications.py    From BoomER with GNU General Public License v3.0 6 votes vote down vote up
def get_apps_values(self, h_key, key_path):
        key = winreg.OpenKey(h_key, key_path, 0, winreg.KEY_READ)
        i = 0
        name = ""
        version = "???"
        while True:
            try:
                subkey = winreg.EnumValue(key, i)
                result = subkey[0]
                if result == "DisplayName":
                    name = subkey[1]
                elif result == "DisplayVersion":
                    version = subkey[1]
                i+=1
            except WindowsError as e:
                break
        if name != "":
            data = name + " ---> " + version
            print(data)
            if self.file_open:
                self.file_open.write(data + "\n")
        winreg.CloseKey(key) 
Example #3
Source File: _registry.py    From pipenv with MIT License 6 votes vote down vote up
def get_all_values(self):
        schema = {}
        for subkey in self:
            schema[subkey.name] = subkey.get_all_values()

        key = winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags)
        try:
            with key:
                for i in count():
                    vname, value, vtype = winreg.EnumValue(key, i)
                    value = get_value_from_tuple(value, vtype)
                    if value:
                        schema[vname or ''] = value
        except OSError:
            pass

        return PythonWrappedDict(schema) 
Example #4
Source File: mapiex.py    From nsf2x with GNU General Public License v2.0 6 votes vote down vote up
def CoCreateInstanceC2R (self, store, reg, clsid, iid) :
        # Ugly code to find DLL in C2R version of COM object and get a COM
        # object despite the fact that COM doesn't handle C2R
        try:
            # Get DLL to load from 2R register 
            aReg = winreg.ConnectRegistry(None, store)
            aKey = winreg.OpenKey(aReg, reg, 0, winreg.KEY_READ | winreg.KEY_WOW64_64KEY)
            dummy_n, IconvDLL, dummy_t = winreg.EnumValue(aKey, 0)
            winreg.CloseKey(aKey)
            winreg.CloseKey(aReg)
            
            # Create OLE object from DLL
            IconvOLE = ctypes.OleDLL(IconvDLL)
            
            # Get COM Instance from OLE 
            clsid_class = uuid.UUID(str(clsid)).bytes_le
            iclassfactory = uuid.UUID(str(pythoncom.IID_IClassFactory)).bytes_le
            com_classfactory = ctypes.c_long(0)
            IconvOLE.DllGetClassObject(clsid_class, iclassfactory, ctypes.byref(com_classfactory))
            MyFactory = pythoncom.ObjectFromAddress(com_classfactory.value, pythoncom.IID_IClassFactory)
            return MyFactory.CreateInstance (None, str(iid))
        except:
            return None 
Example #5
Source File: wmi.py    From opsbro with MIT License 6 votes vote down vote up
def regkey_value(path, name="", start_key=None):
    if isinstance(path, str):
        path = path.split("\\")
    if start_key is None:
        start_key = getattr(winreg, path[0])
        return regkey_value(path[1:], name, start_key)
    else:
        subkey = path.pop(0)
    with winreg.OpenKey(start_key, subkey) as handle:
        assert handle
        if path:
            return regkey_value(path, name, handle)
        else:
            desc, i = None, 0
            while not desc or desc[0] != name:
                desc = winreg.EnumValue(handle, i)
                i += 1
            return desc[1] 
Example #6
Source File: reader.py    From pypykatz with MIT License 6 votes vote down vote up
def list_values(self, key):
		if self.root is None:
			self.setup()
		
		values = []
		i = 0
		while True:
			try:
				value = winreg.EnumValue(key, i)
				values.append(value[0].encode())
				i+= 1
			except OSError as e:
				if isinstance(e, WindowsError) and e.winerror == 259:
					break
				else:
					raise e
				
		return values 
Example #7
Source File: _registry.py    From pythonfinder with MIT License 6 votes vote down vote up
def get_all_values(self):
        schema = {}
        for subkey in self:
            schema[subkey.name] = subkey.get_all_values()

        key = winreg.OpenKeyEx(self._root, self.subkey, 0, winreg.KEY_READ | self._flags)
        try:
            with key:
                for i in count():
                    vname, value, vtype = winreg.EnumValue(key, i)
                    value = get_value_from_tuple(value, vtype)
                    if value:
                        schema[vname or ''] = value
        except OSError:
            pass

        return PythonWrappedDict(schema) 
Example #8
Source File: Environment.py    From EventGhost with GNU General Public License v2.0 6 votes vote down vote up
def GetLatest():
        result = {}

        for key, subkey in Environment.KEY_LIST:
            try:
                i = 0
                with winreg.OpenKey(key, subkey) as hand:
                    while True:
                        var, val = winreg.EnumValue(hand, i)[:2]
                        if var not in Environment.IGNORE_LIST:
                            if var.upper() == "PATH":
                                if "PATH" in result:
                                    result["PATH"] += os.pathsep + val
                                else:
                                    result["PATH"] = val
                            else:
                                result[var] = val
                        i += 1
            except WindowsError:
                pass

        return Environment.Sort(result) 
Example #9
Source File: helper.py    From skcom with MIT License 6 votes vote down vote up
def reg_list_value(key, root=winreg.HKEY_LOCAL_MACHINE):
    """
    列舉機碼下的所有值
    """
    i = 0
    values = {}
    handle = winreg.OpenKey(root, key)

    while True:
        try:
            (vname, value, _) = winreg.EnumValue(handle, i)
            if vname == '':
                vname = '(default)'
            values[vname] = value
            i += 1
        except OSError:
            # winreg.EnumValue(handle, i) 的 i 超出範圍
            break

    winreg.CloseKey(handle)
    return values 
Example #10
Source File: Windows.py    From keyrings.alt with MIT License 6 votes vote down vote up
def _delete_key_if_empty(self, service):
        key_name = self._key_for_service(service)
        key = winreg.OpenKey(
            winreg.HKEY_CURRENT_USER, key_name, 0, winreg.KEY_ALL_ACCESS
        )
        try:
            winreg.EnumValue(key, 0)
            return
        except WindowsError:
            pass
        winreg.CloseKey(key)

        # it's empty; delete everything
        while key_name != 'Software':
            parent, sep, base = key_name.rpartition('\\')
            key = winreg.OpenKey(
                winreg.HKEY_CURRENT_USER, parent, 0, winreg.KEY_ALL_ACCESS
            )
            winreg.DeleteKey(key, base)
            winreg.CloseKey(key)
            key_name = parent 
Example #11
Source File: nsf2x.py    From nsf2x with GNU General Public License v2.0 5 votes vote down vote up
def OutlookPath():
    """Function to retrieve the path to Outlook from the registry"""
    aReg = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
    aKey = winreg.OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE")
    # prepend unused variables with "dummy_" to keep PyLint happy
    dummy_n, v, dummy_t = winreg.EnumValue(aKey, 0)
    winreg.CloseKey(aKey)
    winreg.CloseKey(aReg)
    return v 
Example #12
Source File: test_winsound.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def has_sound(sound):
    """Find out if a particular event is configured with a default sound"""
    try:
        # Ask the mixer API for the number of devices it knows about.
        # When there are no devices, PlaySound will fail.
        if ctypes.windll.winmm.mixerGetNumDevs() == 0:
            return False

        key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER,
                "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound))
        return winreg.EnumValue(key, 0)[1] != ""
    except OSError:
        return False 
Example #13
Source File: win32.py    From bazarr with GNU General Public License v3.0 5 votes vote down vote up
def valuestodict(key):
    """Convert a registry key's values to a dictionary."""
    dict = {}
    size = winreg.QueryInfoKey(key)[1]
    for i in range(size):
        data = winreg.EnumValue(key, i)
        dict[data[0]] = data[1]
    return dict 
Example #14
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 #15
Source File: environment.py    From natto-py with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def __regkey_value(self, path, name='', start_key=None):
        r'''Return the data of value mecabrc at MeCab HKEY node.

        On Windows, the path to the mecabrc as set in the Windows Registry is
        used to deduce the path to libmecab.dll.

        Returns:
            The full path to the mecabrc on Windows.

        Raises:
            WindowsError: A problem was encountered in trying to locate the
                value mecabrc at HKEY_CURRENT_USER\Software\MeCab.
        '''
        if sys.version < '3':
            import _winreg as reg
        else:
            import winreg as reg

        def _fn(path, name='', start_key=None):
            if isinstance(path, str):
                path = path.split('\\')
            if start_key is None:
                start_key = getattr(reg, path[0])
                return _fn(path[1:], name, start_key)
            else:
                subkey = path.pop(0)
            with reg.OpenKey(start_key, subkey) as handle:
                if path:
                    return _fn(path, name, handle)
                else:
                    desc, i = None, 0
                    while not desc or desc[0] != name:
                        desc = reg.EnumValue(handle, i)
                        i += 1
                    return desc[1]
        return _fn(path, name, start_key) 
Example #16
Source File: _win32.py    From pySINDy with MIT License 5 votes vote down vote up
def valuestodict(key):
    """Convert a registry key's values to a dictionary."""
    dict = {}
    size = winreg.QueryInfoKey(key)[1]
    for i in range(size):
        data = winreg.EnumValue(key, i)
        dict[data[0]] = data[1]
    return dict 
Example #17
Source File: postinstall_simnibs.py    From simnibs with GNU General Public License v3.0 5 votes vote down vote up
def _get_win_simnibs_env_vars():
    ''' 'Creates a disctionary with environment names and values '''
    simnibs_env_vars = {}
    with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment') as reg:
        _, num_values, _ = winreg.QueryInfoKey(reg)
        for i in range(num_values):
            var_name, value, _ = winreg.EnumValue(reg, i)
            if 'SIMNIBS' in var_name:
                simnibs_env_vars[var_name] = value
    return simnibs_env_vars 
Example #18
Source File: tzwin.py    From mxnet-lambda with Apache License 2.0 5 votes vote down vote up
def valuestodict(key):
    """Convert a registry key's values to a dictionary."""
    dict = {}
    size = winreg.QueryInfoKey(key)[1]
    for i in range(size):
        data = winreg.EnumValue(key, i)
        dict[data[0]] = data[1]
    return dict 
Example #19
Source File: win32.py    From xbmc-addons-chinese with GNU General Public License v2.0 5 votes vote down vote up
def valuestodict(key):
    """Convert a registry key's values to a dictionary."""
    dict = {}
    size = winreg.QueryInfoKey(key)[1]
    for i in range(size):
        data = winreg.EnumValue(key, i)
        dict[data[0]] = data[1]
    return dict 
Example #20
Source File: win32.py    From plugin.video.iptv.recorder with GNU General Public License v3.0 5 votes vote down vote up
def valuestodict(key):
    """Convert a registry key's values to a dictionary."""
    dict = {}
    size = winreg.QueryInfoKey(key)[1]
    for i in range(size):
        data = winreg.EnumValue(key, i)
        dict[data[0]] = data[1]
    return dict 
Example #21
Source File: __init__.py    From pypot with GNU General Public License v3.0 5 votes vote down vote up
def _get_available_ports():
    """ Tries to find the available serial ports on your system. """
    if platform.system() == 'Darwin':
        return glob.glob('/dev/tty.usb*')

    elif platform.system() == 'Linux':
        return glob.glob('/dev/ttyACM*') + glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyAMA*')

    elif sys.platform.lower() == 'cygwin':
        return glob.glob('/dev/com*')

    elif platform.system() == 'Windows':
        import winreg
        import itertools

        ports = []
        path = 'HARDWARE\\DEVICEMAP\\SERIALCOMM'
        key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)

        for i in itertools.count():
            try:
                ports.append(str(winreg.EnumValue(key, i)[1]))
            except WindowsError:
                return ports
    else:
        raise EnvironmentError('{} is an unsupported platform, cannot find serial ports!'.format(platform.system()))
    return [] 
Example #22
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 #23
Source File: win32.py    From komodo-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def valuestodict(key):
    """Convert a registry key's values to a dictionary."""
    dict = {}
    size = winreg.QueryInfoKey(key)[1]
    for i in range(size):
        data = winreg.EnumValue(key, i)
        dict[data[0]] = data[1]
    return dict 
Example #24
Source File: tzwin.py    From jx-sqlite with Mozilla Public License 2.0 5 votes vote down vote up
def valuestodict(key):
    """Convert a registry key's values to a dictionary."""
    dict = {}
    size = winreg.QueryInfoKey(key)[1]
    for i in range(size):
        data = winreg.EnumValue(key, i)
        dict[data[0]] = data[1]
    return dict 
Example #25
Source File: test_winsound.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def has_sound(sound):
    """Find out if a particular event is configured with a default sound"""
    try:
        # Ask the mixer API for the number of devices it knows about.
        # When there are no devices, PlaySound will fail.
        if ctypes.windll.winmm.mixerGetNumDevs() == 0:
            return False

        key = winreg.OpenKeyEx(winreg.HKEY_CURRENT_USER,
                "AppEvents\Schemes\Apps\.Default\{0}\.Default".format(sound))
        return winreg.EnumValue(key, 0)[1] != ""
    except OSError:
        return False 
Example #26
Source File: font_manager.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def win32InstalledFonts(directory=None, fontext='ttf'):
    """
    Search for fonts in the specified font directory, or use the
    system directories if none given.  A list of TrueType font
    filenames are returned by default, or AFM fonts if *fontext* ==
    'afm'.
    """
    import winreg

    if directory is None:
        directory = win32FontDirectory()

    fontext = ['.' + ext for ext in get_fontext_synonyms(fontext)]

    items = set()
    for fontdir in MSFontDirectories:
        try:
            with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir) as local:
                for j in range(winreg.QueryInfoKey(local)[1]):
                    key, direc, tp = winreg.EnumValue(local, j)
                    if not isinstance(direc, str):
                        continue
                    # Work around for https://bugs.python.org/issue25778, which
                    # is fixed in Py>=3.6.1.
                    direc = direc.split("\0", 1)[0]
                    try:
                        path = Path(directory, direc).resolve()
                    except (FileNotFoundError, RuntimeError):
                        # Don't fail with invalid entries (FileNotFoundError is
                        # only necessary on Py3.5).
                        continue
                    if path.suffix.lower() in fontext:
                        items.add(str(path))
        except (OSError, MemoryError):
            continue
    return list(items) 
Example #27
Source File: regobj.py    From NVDARemote with GNU General Public License v2.0 5 votes vote down vote up
def next(self):
        try:
            v = _winreg.EnumValue(self.key.hkey,self.index)
        except WindowsError:
            raise StopIteration
        else:
            self.index += 1
            return Value(v[1],v[0],v[2]) 
Example #28
Source File: font_manager.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def win32InstalledFonts(directory=None, fontext='ttf'):
    """
    Search for fonts in the specified font directory, or use the
    system directories if none given.  A list of TrueType font
    filenames are returned by default, or AFM fonts if *fontext* ==
    'afm'.
    """
    import winreg

    if directory is None:
        directory = win32FontDirectory()

    fontext = ['.' + ext for ext in get_fontext_synonyms(fontext)]

    items = set()
    for fontdir in MSFontDirectories:
        try:
            with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir) as local:
                for j in range(winreg.QueryInfoKey(local)[1]):
                    key, direc, tp = winreg.EnumValue(local, j)
                    if not isinstance(direc, str):
                        continue
                    # Work around for https://bugs.python.org/issue25778, which
                    # is fixed in Py>=3.6.1.
                    direc = direc.split("\0", 1)[0]
                    try:
                        path = Path(directory, direc).resolve()
                    except (FileNotFoundError, RuntimeError):
                        # Don't fail with invalid entries (FileNotFoundError is
                        # only necessary on Py3.5).
                        continue
                    if path.suffix.lower() in fontext:
                        items.add(str(path))
        except (OSError, MemoryError):
            continue
    return list(items) 
Example #29
Source File: font_manager.py    From GraphicDesignPatternByPython with MIT License 5 votes vote down vote up
def win32InstalledFonts(directory=None, fontext='ttf'):
    """
    Search for fonts in the specified font directory, or use the
    system directories if none given.  A list of TrueType font
    filenames are returned by default, or AFM fonts if *fontext* ==
    'afm'.
    """

    import winreg

    if directory is None:
        directory = win32FontDirectory()

    fontext = get_fontext_synonyms(fontext)

    items = set()
    for fontdir in MSFontDirectories:
        try:
            with winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, fontdir) as local:
                for j in range(winreg.QueryInfoKey(local)[1]):
                    key, direc, tp = winreg.EnumValue(local, j)
                    if not isinstance(direc, str):
                        continue
                    # Work around for https://bugs.python.org/issue25778, which
                    # is fixed in Py>=3.6.1.
                    direc = direc.split("\0", 1)[0]
                    path = Path(directory, direc).resolve()
                    if path.suffix.lower() in fontext:
                        items.add(str(path))
                return list(items)
        except (OSError, MemoryError):
            continue
    return None 
Example #30
Source File: windows.py    From mbed-os-tools with Apache License 2.0 5 votes vote down vote up
def _iter_vals(key):
    """! Iterate over values of a key
    """
    logger.debug("_iter_vals %r", key)
    for i in range(winreg.QueryInfoKey(key)[1]):
        yield winreg.EnumValue(key, i)