當前位置: 首頁>>代碼示例>>Python>>正文


Python winreg.OpenKey方法代碼示例

本文整理匯總了Python中winreg.OpenKey方法的典型用法代碼示例。如果您正苦於以下問題:Python winreg.OpenKey方法的具體用法?Python winreg.OpenKey怎麽用?Python winreg.OpenKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在winreg的用法示例。


在下文中一共展示了winreg.OpenKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: is_using_dcs_steam_edition

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def is_using_dcs_steam_edition():
    """
    Check if DCS World : Steam Edition version is installed on this computer
    :return True if DCS Steam edition is installed,
            -1 if DCS Steam Edition is registered in Steam apps but not installed,
            False if never installed in Steam
    """
    if not is_windows_os:
        return False
    try:
        # Note : Steam App ID for DCS World is 223750
        dcs_steam_app_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Valve\\Steam\\Apps\\223750")
        installed = winreg.QueryValueEx(dcs_steam_app_key, "Installed")
        winreg.CloseKey(dcs_steam_app_key)
        if installed[0] == 1:
            return True
        else:
            return False
    except FileNotFoundError as fnfe:
        return False 
開發者ID:pydcs,項目名稱:dcs,代碼行數:22,代碼來源:installation.py

示例2: is_using_dcs_standalone_edition

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def is_using_dcs_standalone_edition():
    """
    Check if DCS World standalone edition is installed on this computer
    :return True if Standalone is installed, False if it is not
    """
    if not is_windows_os:
        return False
    try:
        dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World")
        winreg.CloseKey(dcs_path_key)
        return True
    except FileNotFoundError as fnfe:
        try:
            dcs_path_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, "Software\\Eagle Dynamics\\DCS World OpenBeta")
            winreg.CloseKey(dcs_path_key)
            return True
        except FileNotFoundError:
            return False 
開發者ID:pydcs,項目名稱:dcs,代碼行數:20,代碼來源:installation.py

示例3: _get_win_folder_from_registry

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def _get_win_folder_from_registry(csidl_name):
    """This is a fallback technique at best. I'm not sure if using the
    registry for this guarantees us the correct answer for all CSIDL_*
    names.
    """
    if PY3:
      import winreg as _winreg
    else:
      import _winreg

    shell_folder_name = {
        "CSIDL_APPDATA": "AppData",
        "CSIDL_COMMON_APPDATA": "Common AppData",
        "CSIDL_LOCAL_APPDATA": "Local AppData",
    }[csidl_name]

    key = _winreg.OpenKey(
        _winreg.HKEY_CURRENT_USER,
        r"Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders"
    )
    dir, type = _winreg.QueryValueEx(key, shell_folder_name)
    return dir 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:24,代碼來源:appdirs.py

示例4: set_windows_path_var

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
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),
        ) 
開發者ID:python-poetry,項目名稱:poetry,代碼行數:26,代碼來源:get-poetry.py

示例5: _find_chrome_win

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def _find_chrome_win():
    import winreg as reg
    reg_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\chrome.exe'

    for install_type in reg.HKEY_CURRENT_USER, reg.HKEY_LOCAL_MACHINE:
        try:
            reg_key = reg.OpenKey(install_type, reg_path, 0, reg.KEY_READ)
            chrome_path = reg.QueryValue(reg_key, None)
            reg_key.Close()
            if not os.path.isfile(chrome_path):
                continue
        except WindowsError:
            chrome_path = None
        else:
            break

    return chrome_path 
開發者ID:samuelhwilliams,項目名稱:Eel,代碼行數:19,代碼來源:chrome.py

示例6: default_cm3d2_dir

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def default_cm3d2_dir(base_dir, file_name, new_ext):
	if not base_dir:
		if preferences().cm3d2_path:
			base_dir = os.path.join(preferences().cm3d2_path, "GameData", "*." + new_ext)
		else:
			try:
				import winreg
				with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r'Software\KISS\カスタムメイド3D2') as key:
					base_dir = winreg.QueryValueEx(key, 'InstallPath')[0]
					preferences().cm3d2_path = base_dir
					base_dir = os.path.join(base_dir, "GameData", "*." + new_ext)
			except: pass
	if file_name:
		base_dir = os.path.join(os.path.split(base_dir)[0], file_name)
	base_dir = os.path.splitext(base_dir)[0] + "." + new_ext
	return base_dir

# 一時ファイル書き込みと自動バックアップを行うファイルオブジェクトを返す 
開發者ID:CM3D2user,項目名稱:Blender-CM3D2-Converter,代碼行數:20,代碼來源:common.py

示例7: get_home_dir

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def get_home_dir(self, username):
            """Return the user's profile directory, the closest thing
            to a user home directory we have on Windows.
            """
            try:
                sid = win32security.ConvertSidToStringSid(
                    win32security.LookupAccountName(None, username)[0])
            except pywintypes.error as err:
                raise AuthorizerError(err)
            path = r"SOFTWARE\Microsoft\Windows NT" \
                   r"\CurrentVersion\ProfileList" + "\\" + sid
            try:
                key = winreg.OpenKey(winreg.HKEY_LOCAL_MACHINE, path)
            except WindowsError:
                raise AuthorizerError(
                    "No profile directory defined for user %s" % username)
            value = winreg.QueryValueEx(key, "ProfileImagePath")[0]
            home = win32api.ExpandEnvironmentStrings(value)
            if not PY3 and not isinstance(home, unicode):
                home = home.decode('utf8')
            return home 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:23,代碼來源:authorizers.py

示例8: get_password

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def get_password(self, service, username):
        """Get password of the username for the service
        """
        try:
            # fetch the password
            key = self._key_for_service(service)
            hkey = winreg.OpenKey(winreg.HKEY_CURRENT_USER, key)
            password_saved = winreg.QueryValueEx(hkey, username)[0]
            password_base64 = password_saved.encode('ascii')
            # decode with base64
            password_encrypted = base64.decodestring(password_base64)
            # decrypted the password
            password = _win_crypto.decrypt(password_encrypted).decode('utf-8')
        except EnvironmentError:
            password = None
        return password 
開發者ID:jaraco,項目名稱:keyrings.alt,代碼行數:18,代碼來源:Windows.py

示例9: proxy_bypass_registry

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def proxy_bypass_registry(host):
        try:
            if is_py3:
                import winreg
            else:
                import _winreg as winreg
        except ImportError:
            return False

        try:
            internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
            # ProxyEnable could be REG_SZ or REG_DWORD, normalizing it
            proxyEnable = int(winreg.QueryValueEx(internetSettings,
                                              'ProxyEnable')[0])
            # ProxyOverride is almost always a string
            proxyOverride = winreg.QueryValueEx(internetSettings,
                                                'ProxyOverride')[0]
        except OSError:
            return False
        if not proxyEnable or not proxyOverride:
            return False

        # make a check value list from the registry entry: replace the
        # '<local>' string by the localhost entry and the corresponding
        # canonical entry.
        proxyOverride = proxyOverride.split(';')
        # now check if we match one of the registry values.
        for test in proxyOverride:
            if test == '<local>':
                if '.' not in host:
                    return True
            test = test.replace(".", r"\.")     # mask dots
            test = test.replace("*", r".*")     # change glob sequence
            test = test.replace("?", r".")      # change glob char
            if re.match(test, host, re.I):
                return True
        return False 
開發者ID:danielecook,項目名稱:gist-alfred,代碼行數:40,代碼來源:utils.py

示例10: _get_win_simnibs_env_vars

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [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

示例11: _get_win_path

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def _get_win_path():
    with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment') as reg:
        try:
            path = winreg.QueryValueEx(reg, 'Path')[0]
        except FileNotFoundError: # PATH not set
            path = ''
    return path 
開發者ID:simnibs,項目名稱:simnibs,代碼行數:9,代碼來源:postinstall_simnibs.py

示例12: path_cleanup

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def path_cleanup():
    ''' Removes SIMNIBS from PATH '''
    if sys.platform in ['linux', 'darwin']:
        bashrc, backup_file = _get_bashrc()

        if not os.path.isfile(bashrc):
            print('Could not find bashrc file')
            return

        print('Removing SimNIBS install from PATH')
        print(f'Backing up the bashrc file at {backup_file}')
        _copy_and_log(bashrc, backup_file)
        with open(backup_file, 'r') as fin:
            with open(bashrc, 'w') as fout:
                for line in fin:
                    if not re.search('simnibs', line, re.IGNORECASE):
                        fout.write(line)
    else:
        simnibs_env_vars = _get_win_simnibs_env_vars()
        path = _get_win_path()
        path = path.split(';')
        path = [p for p in path if len(p) > 0]
        for key, value in simnibs_env_vars.items():
            # If the directory is in the PATH variable, remove it
            path = [
                os.path.normpath(p) for p in path if not (
                os.path.normpath(value) in os.path.normpath(p))]
            # Remove environment variable
            with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
                winreg.DeleteValue(reg, key)

        # write out the PATH with SimNIBS removed
        with winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Environment', access=winreg.KEY_WRITE) as reg:
            path = ';'.join(path) + ';'
            winreg.SetValueEx(reg,'Path', 0, winreg.REG_EXPAND_SZ, path) 
開發者ID:simnibs,項目名稱:simnibs,代碼行數:37,代碼來源:postinstall_simnibs.py

示例13: uninstaller_cleanup

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def uninstaller_cleanup():
    if sys.platform == 'win32':
        try:
            with winreg.OpenKey(
                winreg.HKEY_CURRENT_USER,
                    r'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
                    access=winreg.KEY_WRITE) as reg:
                winreg.DeleteKey(reg, 'SimNIBS')
        except FileNotFoundError:
            pass 
開發者ID:simnibs,項目名稱:simnibs,代碼行數:12,代碼來源:postinstall_simnibs.py

示例14: set_envvar_in_registry

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
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) 
開發者ID:coala,項目名稱:coala-quickstart,代碼行數:11,代碼來源:store_env_in_registry.py

示例15: proxy_bypass_registry

# 需要導入模塊: import winreg [as 別名]
# 或者: from winreg import OpenKey [as 別名]
def proxy_bypass_registry(host):
        if is_py3:
            import winreg
        else:
            import _winreg as winreg
        try:
            internetSettings = winreg.OpenKey(winreg.HKEY_CURRENT_USER,
                r'Software\Microsoft\Windows\CurrentVersion\Internet Settings')
            proxyEnable = winreg.QueryValueEx(internetSettings,
                                              'ProxyEnable')[0]
            proxyOverride = winreg.QueryValueEx(internetSettings,
                                                'ProxyOverride')[0]
        except OSError:
            return False
        if not proxyEnable or not proxyOverride:
            return False

        # make a check value list from the registry entry: replace the
        # '<local>' string by the localhost entry and the corresponding
        # canonical entry.
        proxyOverride = proxyOverride.split(';')
        # now check if we match one of the registry values.
        for test in proxyOverride:
            if test == '<local>':
                if '.' not in host:
                    return True
            test = test.replace(".", r"\.")     # mask dots
            test = test.replace("*", r".*")     # change glob sequence
            test = test.replace("?", r".")      # change glob char
            if re.match(test, host, re.I):
                return True
        return False 
開發者ID:getavalon,項目名稱:core,代碼行數:34,代碼來源:utils.py


注:本文中的winreg.OpenKey方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。