;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       GetDefBrowser() 
;; 
;;ACTION         Returns a 3-element array with the default browser name, version, and path 
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2019/10/15 
;; 
;;HISTORY        1.0  - 2019/10/15 - Initial Release 
;;               1.0a - Fix MS Edge detection process, update example 
;; 
;;SYNTAX         GetDefBrowser() 
;; 
;;PARAMETERS     none 
;; 
;;REMARKS        Returns an array containing the default browser name, version, and command path 
;; 
;;RETURNS        Array 
;; 
;;DEPENDENCIES   GetExtFileProperties() UDF 
;; 
;;TESTED WITH    W2K8, W2K12, W2K16, W7, W8, W10 
;; 
;;EXAMPLES       ; Open a session in the default browser 
;;               $Website = 'https://www.google.com' 
;;               $DBCmd = GetDefBrowser()[2] 
;;               $DBCmd = Replace($DBCmd, '"%1"', $Website) 
;;               Run '%COMSPEC% /c ' + $DBCmd 
; 
Function GetDefBrowser()
 
  Dim $_BrowserCmd, $_AltCmd				; Browser EXE path 
  Dim $_Browser                                         ; Browser to check 
  Dim $_DBrowser					; Default Browser 
  Dim $_Ver                                             ; Version of Default Browser 
 
  $_DBrowser = ''					; default is not set 
 
  ; Process the Windows 10 method first 
  $_Browser = ReadValue('HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice', 'ProgId')
 
  Select
   Case InStr($_Browser, 'app') = 1
    $_DBrowser = 'Microsoft Edge'
    $_BrowserCmd = '"C:\Windows\SystemApps\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\MicrosoftEdge.exe" "%1"'
    $_AltCmd = 'start microsoft-edge:"%1"'
   Case InStr($_Browser, 'firefox')
    $_DBrowser = 'Mozilla Firefox'
    $_BrowserCmd = ReadValue('HKEY_CLASSES_ROOT\' + $_Browser + '\shell\open\command', '')
   Case InStr($_Browser, 'chrome')
    $_DBrowser = 'Google Chrome'
    $_BrowserCmd = ReadValue('HKEY_CLASSES_ROOT\' + $_Browser + '\shell\open\command', '')
   Case InStr($_Browser, 'safari')
    $_DBrowser = 'Apple Safari'
    $_BrowserCmd = ReadValue('HKEY_CLASSES_ROOT\' + $_Browser + '\shell\open\command', '')
   Case InStr($_Browser, 'opera')
    $_DBrowser = 'Opera'
    $_BrowserCmd = ReadValue('HKEY_CLASSES_ROOT\' + $_Browser + '\shell\open\command', '')
   Case InStr($_Browser, 'brave')
    $_DBrowser = 'Brave'
    $_BrowserCmd = ReadValue('HKEY_CLASSES_ROOT\' + $_Browser + '\shell\open\command', '')
;   Case InStr($_Browser, '') 
;    $_DBrowser = '' 
;    $_BrowserCmd = ReadValue('HKEY_CLASSES_ROOT\' + $_Browser + '\shell\open\command', '') 
   Case InStr($_Browser, 'ie')
    $_DBrowser = 'Internet Explorer'
    $_BrowserCmd = ReadValue('HKEY_CLASSES_ROOT\' + $_Browser + '\shell\open\command', '')
  EndSelect
 
  ; Process the Windows 7/8 version method if not detected above 
  If Not $_DBrowser
    $_BrowserCmd = ReadValue('HKEY_CURRENT_USER\Software\Classes\http\shell\open\command', '')
    If $_BrowserCmd
      If Not Exist(Replace($_BrowserCmd, '"', ''))					; revert to IE if not defined 
        $_BrowserCmd = '"C:\Program Files\Internet Explorer\iexplore.exe" "%1"'
      EndIf
    Else
      $_BrowserCmd = '"C:\Program Files\Internet Explorer\iexplore.exe" "%1"'
    EndIf
 
    Select
     Case InStr($_Browser, 'chrome.exe')
      $_DBrowser = 'Google Chrome'
     Case InStr($_Browser, 'firefox.exe')
      $_DBrowser = 'Mozilla Firefox'
     Case InStr($_Browser, 'Brave.exe')
      $_DBrowser = 'Brave'
     Case InStr($_Browser, 'iexplore.exe')
      $_DBrowser = 'Internet Explorer'
    EndSelect
  EndIf
 
  ; Make sure that the arg is consistently formatted as "%1" 
  If Not InStr($_BrowserCmd, '"%1"') $_BrowserCmd = Replace($_BrowserCmd, '%1', '"%1"') EndIf
 
  ; Get just the browser path 
  $_Browser = Replace(Trim(Left($_BrowserCmd, InStr($_BrowserCmd, '.exe"') + 4)), '"', '')
  ; Get the version string from the EXE 
  $_Ver = GetExtFileProperties($_Browser, 'File version')
  ; Replace BrowserCmd value if an alt command is needed to start the app 
  $_BrowserCmd = IIf($_AltCmd, $_AltCmd, $_BrowserCmd)
 
  ; Return the Default Browser Name, Version, and Start Command 
  $GetDefBrowser = $_DBrowser, $_Ver, $_BrowserCmd
  
  Exit 0
  
EndFunction