Advertisement
steve-shambles-2109

168-What browsers are installed

Oct 15th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. """
  2. Python code snippets vol 34:
  3. Windows only
  4. 168-What browsers are installed
  5. stevepython.wordpress.com
  6.  
  7. Source:
  8. https://programtalk.com/python-examples/winreg.HKEY_LOCAL_MACHINE/?ipage=3
  9. """
  10. import winreg
  11.  
  12. def find_windows_browsers():
  13.     """ Access the windows registry to determine
  14.    what browsers are on the system.
  15.    """
  16.     HKLM = winreg.HKEY_LOCAL_MACHINE
  17.     subkey = r'Software\Clients\StartMenuInternet'
  18.     read32 = winreg.KEY_READ | winreg.KEY_WOW64_32KEY
  19.     read64 = winreg.KEY_READ | winreg.KEY_WOW64_64KEY
  20.     key32 = winreg.OpenKey(HKLM, subkey, access=read32)
  21.     key64 = winreg.OpenKey(HKLM, subkey, access=read64)
  22.  
  23.     # Return a list of browsers found in the registry
  24.     # Check if there are any different browsers in the
  25.     # 32 bit location instead of the 64 bit location.
  26.     browsers = []
  27.     i = 0
  28.     while True:
  29.         try:
  30.             browsers.append(winreg.EnumKey(key32, i))
  31.         except EnvironmentError:
  32.             break
  33.         i += 1
  34.  
  35.     i = 0
  36.     while True:
  37.         try:
  38.             browsers.append(winreg.EnumKey(key64, i))
  39.         except EnvironmentError:
  40.             break
  41.         i += 1
  42.  
  43.     winreg.CloseKey(key32)
  44.     winreg.CloseKey(key64)
  45.     print(browsers)
  46.     return browsers
  47.  
  48. find_windows_browsers()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement