如何使用python获取默认浏览器名称?

如何使用python获取默认浏览器名称?,python,python-3.x,browser,windows-10,Python,Python 3.x,Browser,Windows 10,以下解决方案(实际上只有一个)对我不起作用: 解决办法是: from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValue # In Py3, this module is called winreg without the underscore with OpenKey(HKEY_CURRENT_USER, r"Software\Classes\http\shell\open\command") as ke

以下解决方案(实际上只有一个)对我不起作用:


解决办法是:

from _winreg import HKEY_CURRENT_USER, OpenKey, QueryValue
# In Py3, this module is called winreg without the underscore

with OpenKey(HKEY_CURRENT_USER,
             r"Software\Classes\http\shell\open\command") as key:
    cmd = QueryValue(key, None)
但不幸的是,在Windows10Pro中,我没有目标注册表值。我试图在Regedit中找到替代键,但没有成功

请看一看,我的注册表实际上包含:
请在windows 10中检查密钥

HKEY|U CURRENT|U USER\SOFTWARE\Microsoft\Windows\Shell\Associations\URLAssociations(http | https)\UserChoice


以下内容在Windows 10 pro上适用:

from winreg import HKEY_CURRENT_USER, OpenKey, QueryValueEx

reg_path = r'Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice'

with OpenKey(HKEY_CURRENT_USER, reg_path) as key:
    print(QueryValueEx(key, 'ProgId'))
结果(首先将Chrome设置为默认值,然后使用IE):

$python test.py ('ChromeHTML',1) $python test.py ('IE.HTTPS',1) Windows 10 Python3可能希望更改“http”而不是https的密钥,但这是我的代码,因为我的上下文是安全服务器的。我想要浏览器的二进制名称和路径,这只是多一行

$ python test.py ('ChromeHTML', 1) $ python test.py ('IE.HTTPS', 1)
def get_windows_default_browser_launch():
    """ On windows, return the default browser for 'https' urls
    returns: example '"C:\Program Files\Mozilla Firefox\firefox.exe" -osint -url "%1"'
    """
    import winreg
    key = winreg.OpenKey(winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER), r"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\https\UserChoice")
    prog_id, _ = winreg.QueryValueEx(key, "ProgId")
    key = winreg.OpenKey(winreg.ConnectRegistry(None, winreg.HKEY_LOCAL_MACHINE), r"SOFTWARE\Classes\{}\shell\open\command".format(prog_id))
    launch_string, _ = winreg.QueryValueEx(key, "")  # read the default value
    return launch_string