Jump to content
TheSaint

Default Browser Switcher

Recommended Posts

Just a little program I thought could be handy.

Alas, for some reason it only works with 3 out of the 7 browsers I have installed ... despite each having their own command that you imagine should work.

It works for - Brave, Slimjet and Chrome.

But not for Firefox, IE, Opera Stable or Opera Developer.

I've tried with and without Admin.

For what it is worth, here it is. Maybe someone can make it work for all.

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <MsgBoxConstants.au3>
#include <Misc.au3>

_Singleton("default-browser-switcher-thsaint")

Global $Button_exit, $Button_info, $Combo_brows, $Group_def, $Group_switch, $Input_def

Global $b, $browser, $browsers, $choices, $default, $defbrowser, $exepth, $foldpth, $inifle
Global $installinfo, $Main_GUI, $message, $name, $params, $path, $pos

$inifle = @ScriptDir & "\Settings.ini"

SplashTextOn("", "Please Wait!", 180, 120, -1, -1, 33)

$defbrowser = RegRead("HKEY_CURRENT_USER\Software\Clients\StartMenuInternet", "")
IniWrite($inifle, "Installed Browsers", "default", $defbrowser)

$browser = ""
$browsers = ""
$b = 1
While 1
    $browser = RegEnumKey("HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet", $b)
    If @error Then ExitLoop
    IniWrite($inifle, "Installed Browsers", "number", $b)
    IniWrite($inifle, $browser, "entry", $browser)
    $name = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\" & $browser, "")
    IniWrite($inifle, $browser, "title", $name)
    If $browser = $defbrowser Then
        ;$default = $name & " (" & $browser & ")"
        $default = $name
        IniWrite($inifle, "Installed Browsers", "title", $name)
    EndIf
    $path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\" & $browser & "\shell\open\command", "")
    IniWrite($inifle, $browser, "path", $path)
    $installinfo = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\" & $browser & "\InstallInfo", "ReinstallCommand")
    IniWrite($inifle, $browser, "switch_command", $installinfo)
    ;
    $browser = $name & " (" & $browser & ")"
    If $browsers = "" Then
        $browsers = $browser
    Else
        $browsers &= "|" & $browser
    EndIf
    ;
    ;MsgBox($MB_SYSTEMMODAL, "Browser #" & $b, $browser)
    $b = $b + 1
WEnd

$choices = StringReplace($browsers, "|", @LF)

SplashOff()

;MsgBox(0, "Browser Details", "Default Browser = " & $default & @LF & @LF & $choices)

; Script generated by GUIBuilder Prototype 0.9
Const $style = BitOR($WS_OVERLAPPED, $WS_CAPTION, $WS_SYSMENU, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_MINIMIZEBOX)
$Main_GUI = GuiCreate("Default Browser Switcher v1.0", 295, 140, -1, -1, $style, $WS_EX_TOPMOST)
; CONTROLS
$Group_def = GuiCtrlCreateGroup("Default Browser", 10, 10, 155, 55)
$Input_def = GuiCtrlCreateInput("", 20, 30, 135, 20)
GUICtrlSetTip($Input_def, "Current default browser!")
;
$Button_info = GuiCtrlCreateButton("Info", 175, 15, 50, 50)
GUICtrlSetFont($Button_info, 9, 600)
GUICtrlSetTip($Button_info, "Program Information!")
;
$Button_exit = GuiCtrlCreateButton("EXIT", 235, 15, 50, 50)
GUICtrlSetFont($Button_exit, 9, 600)
GUICtrlSetTip($Button_info, "Exit or Quit the program!")
;
$Group_switch = GuiCtrlCreateGroup("Switch To", 10, 75, 275, 55)
$Combo_brows = GUICtrlCreateCombo("", 20, 95, 255, 21)
GUICtrlSetTip($Combo_brows, "Switch to selected browser!")
;
; SETTINGS
GUICtrlSetData($Input_def, $default)
;
GUICtrlSetData($Combo_brows, $browsers, $default & " (" & $defbrowser & ")")


GuiSetState(@SW_SHOWNORMAL)
Do
    Switch GuiGetMsg()
        Case $GUI_EVENT_CLOSE, $Button_exit
            ; Exit or Quit the program
            GUIDelete($Main_GUI)
            ExitLoop
        Case $Button_info
            ; Program Information
            $message = "This program allows you to switch from one installed browser to another, using that browser's own 'Set As Default' command."
            MsgBox($MB_OK + $MB_ICONINFORMATION + $MB_TOPMOST, "Program Information", $message, 0, $Main_GUI)
        Case $Combo_brows
            ; Switch to selected browser
            $browser = GUICtrlRead($Combo_brows)
            $browser = StringSplit($browser, " (", 1)
            $name = $browser[1]
            $browser = StringTrimRight($browser[$browser[0]], 1)
            $default = $name
            GUICtrlSetData($Input_def, $default)
            SplashTextOn("", "New Default Browser", 200, 120, -1, -1, 33)
            $installinfo = IniRead($inifle, $browser, "switch_command", "")
            $installinfo = StringSplit($installinfo, '" ', 1)
            $exepth = $installinfo[1]
            $exepth = StringReplace($exepth, '"', '')
            $pos = StringInStr($exepth, "\", 0, -1)
            $foldpth = StringLeft($exepth, $pos - 1)
            If $browser = "FIREFOX.EXE" Then
                $params = "/SetAsDefaultAppUser"
            Else
                $params = $installinfo[2]
            EndIf
            ;MsgBox($MB_OK + $MB_ICONINFORMATION + $MB_TOPMOST, "New Default Browser", $browser & @LF & $exepth & @LF & $params & @LF & $foldpth, 2, $Main_GUI)
            If FileExists($exepth) Then
                ShellExecuteWait($exepth, $params, $foldpth)
                ;RunWait($exepth & " " & $params, $foldpth)
                SplashOff()
                GUIDelete($Main_GUI)
                ExitLoop
            Else
                MsgBox($MB_OK + $MB_ICONERROR + $MB_TOPMOST, "Switch Error", "Browser path does not exist.", 0, $Main_GUI)
            EndIf
        Case Else
            ;
    EndSwitch
Until False

Exit

Just for the record, here are the commands for each browser I have installed, as gleaned from the Registry - HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet.

Brave - "C:\Program Files\BraveSoftware\Brave-Browser\Application\brave.exe" --make-default-browser

Firefox - "C:\Program Files\Mozilla Firefox\uninstall\helper.exe" /SetAsDefaultAppGlobal

Slimjet Browser - "C:\Program Files\Slimjet\slimjet.exe" --make-default-browser

Chrome - "C:\Users\ThSaint\AppData\Local\Google\Chrome\Application\chrome.exe" --make-default-browser

IE - "C:\Windows\System32\ie4uinit.exe" -reinstall

Opera Stable - "C:\Program Files\Opera\Launcher.exe" --makedefaultbrowser

Opera Developer - "C:\Program Files\Opera developer\Launcher.exe" --makedefaultbrowser

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Found a solution for Firefox ... code in first post has been amended.

DID NOT WORK"C:\Program Files\Mozilla Firefox\uninstall\helper.exe" /SetAsDefaultAppGlobal

DID WORK - "C:\Program Files\Mozilla Firefox\uninstall\helper.exe" /SetAsDefaultAppUser

/SetAsDefaultAppUser works only for the current user.

Chasing up something similar for IE and Opera now ... wish me luck.

Edited by TheSaint

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

@TheSaint.  Cool UDF.  I figured I would offer a suggestion if you have not already found out how to get the other browsers to work.  If I were in your shoes, I would use a tool like Nirsoft's reg from app tool or registry changes view tool to determine which registry keys are responsible for setting each browser as the "default browser" by actually recording the change that is made.  Just a thought

Share this post


Link to post
Share on other sites

Thanks for the suggestion, but I doubt I will bother any time soon ... too much on my plate etc.

But if others are happy to chase it up and post each solution here, I will be happy to incorporate. :)


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...