Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: what_browser_is_default.py
- # Version: 1.00
- # Author: Jeoi Reqi
- """
- This script retrieves the default web browser set in the Windows registry.
- Requirements:
- - This script is designed for Windows operating systems.
- - Python must be installed on the system.
- - The script requires access to the Windows registry.
- """
- import os
- import winreg
- def get_default_browser_windows():
- try:
- # Open the Windows registry key for HTTP associations
- with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice") as key:
- # Read the ProgId value
- prog_id, _ = winreg.QueryValueEx(key, 'ProgId')
- # Open the registry key for the ProgId
- with winreg.OpenKey(winreg.HKEY_CLASSES_ROOT, f"\\{prog_id}\\shell\\open\\command") as browser_key:
- # Read the default browser path
- browser_path, _ = winreg.QueryValueEx(browser_key, '')
- # Extract the clean path to the browser executable (remove command-line arguments)
- browser_path = browser_path.split('"')[1]
- return os.path.basename(browser_path), browser_path
- except Exception as e:
- print("Error:", e)
- return None, None
- def main():
- default_browser, default_browser_path = get_default_browser_windows()
- if default_browser:
- print("Default Browser:")
- print("Name:", default_browser)
- print("Path:", default_browser_path)
- else:
- print("Default browser not found.")
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement