如何使用python获取默认的浏览器名称? [英] How to get default browser name using python?
本文介绍了如何使用python获取默认的浏览器名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下解决方案(实际上只有一种)对我不起作用:
解决方案以下内容在Windows 10专业版中对我有效:
从winreg导入HKEY_CURRENT_USER,OpenKey,QueryValueEx
reg_path = r'Software\Microsoft\Windows\Shell\Associations\ \UrlAssociations\https\UserChoice'
以OpenKey(HKEY_CURRENT_USER,reg_path)作为键:
print(QueryValueEx(key,'ProgId'))
结果(首先将Chrome设置为默认值,然后使用IE):
$ python test.py
('ChromeHTML',1)
$ python test.py
('IE.HTTPS',1)
Following solutions (actually it is only one) doesn't work to me :
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:
解决方案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)
这篇关于如何使用python获取默认的浏览器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文