2

Following solutions (actually it is only one) doesn't work to me :

How to get a name of default browser using python


How to get name of the default browser in windows using python?

Solution was:

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)

But unfortunately, in Windows 10 Pro I don't have targeted registry value. I've tried to find alternative keys in Regedit, but no luck.

Please take a look, what my registry virtually contains: enter image description here

martineau
  • 119,623
  • 25
  • 170
  • 301
Quanti Monati
  • 769
  • 1
  • 11
  • 35

3 Answers3

2

The following works for me on 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'))

Result (first with Chrome set as default, then with IE):

$ python test.py
('ChromeHTML', 1)

$ python test.py
('IE.HTTPS', 1)
cody
  • 11,045
  • 3
  • 21
  • 36
1

Please check for the key in windows 10

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\URLAssociations(http|https)\UserChoice

0
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

Windows 10 Python3 , may want to change the key for 'http' not https, but this is my code verbatim as my context is of a secured server. I wanted the browser binary name and path, which is just one more line.