当前位置: 首页>>代码示例>>Python>>正文


Python winreg.QueryInfoKey方法代码示例

本文整理汇总了Python中winreg.QueryInfoKey方法的典型用法代码示例。如果您正苦于以下问题:Python winreg.QueryInfoKey方法的具体用法?Python winreg.QueryInfoKey怎么用?Python winreg.QueryInfoKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在winreg的用法示例。


在下文中一共展示了winreg.QueryInfoKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_launcher_install_path

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def _get_launcher_install_path(self) -> Optional[str]:
        if is_windows():

            try:
                for h_root in (winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE):
                    with winreg.OpenKey(h_root, r"Software\Microsoft\Windows\CurrentVersion\Uninstall") as h_apps:
                        for idx in range(winreg.QueryInfoKey(h_apps)[0]):
                            try:
                                with winreg.OpenKeyEx(h_apps, winreg.EnumKey(h_apps, idx)) as h_app_info:
                                    def get_value(key):
                                        return winreg.QueryValueEx(h_app_info, key)[0]

                                    if get_value("DisplayName") == self._LAUNCHER_DISPLAY_NAME:
                                        installer_path = get_value("InstallLocation")
                                        if os.path.exists(str(installer_path)):
                                            return installer_path

                            except (WindowsError, KeyError, ValueError):
                                continue

            except (WindowsError, KeyError, ValueError):
                logging.exception("Failed to get client install location")
                return None
        else:
            return None 
开发者ID:nyash-qq,项目名称:galaxy-plugin-twitch,代码行数:27,代码来源:twitch_launcher_client.py

示例2: _iterate_new_uninstall_keys

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def _iterate_new_uninstall_keys(self):
        for arch_key in self._ARCH_KEYS:
            for hive in self._LOOKUP_REGISTRY_HIVES:
                with winreg.OpenKey(hive, self._UNINSTALL_LOCATION, 0, winreg.KEY_READ | arch_key) as key:
                    subkeys = winreg.QueryInfoKey(key)[0]

                    cached_subkeys = self.__keys_count[hive | arch_key]
                    self.__keys_count[hive | arch_key] = subkeys
                    if subkeys <= cached_subkeys:
                        continue  # same or lower number of installed programs since last refresh
                    logging.info(f'New keys in registry {hive | arch_key}: {subkeys}. Reparsing.')

                    for i in range(subkeys):
                        subkey_name = winreg.EnumKey(key, i)
                        if self._ignore_filter and self._ignore_filter(subkey_name):
                            logging.debug(f'Filtred out subkey: {subkey_name}')
                            continue
                        with winreg.OpenKey(key, subkey_name) as subkey:
                            yield (subkey_name, subkey) 
开发者ID:UncleGoogle,项目名称:galaxy-integration-humblebundle,代码行数:21,代码来源:reg_watcher.py

示例3: _get_win_simnibs_env_vars

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
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 
开发者ID:simnibs,项目名称:simnibs,代码行数:12,代码来源:postinstall_simnibs.py

示例4: __len__

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def __len__(self):
        """len() gives the number of values and subkeys."""
        info = _winreg.QueryInfoKey(self.hkey)
        return info[0] + info[1] 
开发者ID:NVDARemote,项目名称:NVDARemote,代码行数:6,代码来源:regobj.py

示例5: valuestodict

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
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 
开发者ID:Schibum,项目名称:sndlatr,代码行数:10,代码来源:_win32.py

示例6: get_cpu_info

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def get_cpu_info():
    reg = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor")
    flag = True
    model_name = ""
    num = _winreg.QueryInfoKey(reg)[0]
    reg2 = _winreg.OpenKeyEx(reg, _winreg.EnumKey(reg, 0))
    model_name = _winreg.QueryValueEx(reg2, 'ProcessorNameString')[0]

    return "{} *{}".format(model_name, num) 
开发者ID:turingsec,项目名称:marsnake,代码行数:11,代码来源:overview_win.py

示例7: list

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def list():
        """Return a list of all time zones known to the system."""
        handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)
        tzkey = winreg.OpenKey(handle, TZKEYNAME)
        result = [winreg.EnumKey(tzkey, i)
                  for i in range(winreg.QueryInfoKey(tzkey)[0])]
        tzkey.Close()
        handle.Close()
        return result 
开发者ID:caronc,项目名称:nzb-subliminal,代码行数:11,代码来源:tzwin.py

示例8: win32InstalledFonts

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
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 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:35,代码来源:font_manager.py

示例9: win32InstalledFonts

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
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) 
开发者ID:holzschu,项目名称:python3_ios,代码行数:38,代码来源:font_manager.py

示例10: _user_sids

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def _user_sids():
    """Map between usernames and the related SID."""
    user_sids = {}

    root_key = winreg.HKEY_LOCAL_MACHINE
    reg_path = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList"

    try:
        log.info("OpenKey on {}, with READ + WOW64".format(reg_path))
        sid_reg = winreg.OpenKey(root_key, reg_path,
                                 0, READ_ACCESS)

    except fnf_exception as error:
        handle_fnf(error)

    if sid_reg:
        subkey_count = winreg.QueryInfoKey(sid_reg)[0]
        for pos in range(subkey_count):
            try:
                sid = winreg.EnumKey(sid_reg, pos)
            except:
                pass
            if sid:
                profile_path_key = "{}\\{}".format(reg_path, sid)
                try:
                    profile_path_reg = winreg.OpenKey(
                        root_key, profile_path_key, 0, READ_ACCESS)

                    profile_path = winreg.QueryValueEx(
                        profile_path_reg, "ProfileImagePath")[0]

                    username = profile_path.split("\\")[-1]
                    user_sids[username] = sid
                except:
                    pass

    return user_sids 
开发者ID:R-ArcGIS,项目名称:r-bridge-install,代码行数:39,代码来源:rpath.py

示例11: WinSoftwareInstalled

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def WinSoftwareInstalled(hive, flag):
    aReg = winreg.ConnectRegistry(None, hive)
    aKey = winreg.OpenKey(aReg, r"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
                          0, winreg.KEY_READ | flag)

    count_subkey = winreg.QueryInfoKey(aKey)[0]

    software_list = []

    for i in range(count_subkey):
        software = {}
        try:
            asubkey_name = winreg.EnumKey(aKey, i)
            asubkey = winreg.OpenKey(aKey, asubkey_name)
            software['name'] = winreg.QueryValueEx(asubkey, "DisplayName")[0]

            try:
                software['version'] = winreg.QueryValueEx(asubkey, "DisplayVersion")[0]
            except EnvironmentError:
                software['version'] = 'undefined'
            try:
                software['publisher'] = winreg.QueryValueEx(asubkey, "Publisher")[0]
            except EnvironmentError:
                software['publisher'] = 'undefined'
            software_list.append(software)
        except EnvironmentError:
            continue

    return software_list 
开发者ID:All4Gis,项目名称:QGISFMV,代码行数:31,代码来源:QgsFmvInstaller.py

示例12: _iter_keys_as_str

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def _iter_keys_as_str(key):
    """! Iterate over subkeys of a key returning subkey as string
    """
    for i in range(winreg.QueryInfoKey(key)[0]):
        yield winreg.EnumKey(key, i) 
开发者ID:ARMmbed,项目名称:mbed-os-tools,代码行数:7,代码来源:windows.py

示例13: _iter_keys

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def _iter_keys(key):
    """! Iterate over subkeys of a key
    """
    for i in range(winreg.QueryInfoKey(key)[0]):
        yield winreg.OpenKey(key, winreg.EnumKey(key, i)) 
开发者ID:ARMmbed,项目名称:mbed-os-tools,代码行数:7,代码来源:windows.py

示例14: _iter_vals

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
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) 
开发者ID:ARMmbed,项目名称:mbed-os-tools,代码行数:8,代码来源:windows.py

示例15: get_localzone_name

# 需要导入模块: import winreg [as 别名]
# 或者: from winreg import QueryInfoKey [as 别名]
def get_localzone_name():
    # Windows is special. It has unique time zone names (in several
    # meanings of the word) available, but unfortunately, they can be
    # translated to the language of the operating system, so we need to
    # do a backwards lookup, by going through all time zones and see which
    # one matches.
    handle = winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE)

    TZLOCALKEYNAME = r'SYSTEM\CurrentControlSet\Control\TimeZoneInformation'
    localtz = winreg.OpenKey(handle, TZLOCALKEYNAME)
    keyvalues = valuestodict(localtz)
    localtz.Close()
    if 'TimeZoneKeyName' in keyvalues:
        # Windows 7 (and Vista?)

        # For some reason this returns a string with loads of NUL bytes at
        # least on some systems. I don't know if this is a bug somewhere, I
        # just work around it.
        tzkeyname = keyvalues['TimeZoneKeyName'].split('\x00', 1)[0]
    else:
        # Windows 2000 or XP

        # This is the localized name:
        tzwin = keyvalues['StandardName']

        # Open the list of timezones to look up the real name:
        TZKEYNAME = r'SOFTWARE\Microsoft\Windows NT\CurrentVersion\Time Zones'
        tzkey = winreg.OpenKey(handle, TZKEYNAME)

        # Now, match this value to Time Zone information
        tzkeyname = None
        for i in range(winreg.QueryInfoKey(tzkey)[0]):
            subkey = winreg.EnumKey(tzkey, i)
            sub = winreg.OpenKey(tzkey, subkey)
            data = valuestodict(sub)
            sub.Close()
            if data['Std'] == tzwin:
                tzkeyname = subkey
                break

        tzkey.Close()
        handle.Close()

    if tzkeyname is None:
        raise LookupError('Can not find Windows timezone configuration')

    timezone = tz_names.get(tzkeyname)
    if timezone is None:
        # Nope, that didn't work. Try adding 'Standard Time',
        # it seems to work a lot of times:
        timezone = tz_names.get(tzkeyname + ' Standard Time')

    # Return what we have.
    if timezone is None:
        raise pytz.UnknownTimeZoneError('Can not find timezone ' + tzkeyname)

    return timezone 
开发者ID:Schibum,项目名称:sndlatr,代码行数:59,代码来源:_win32.py


注:本文中的winreg.QueryInfoKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。