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

3 Answers 3

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)
Sign up to request clarification or add additional context in comments.

Comments

1

Please check for the key in windows 10

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

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.