Default browser?

Discussion in 'Excel Programming' started by Charlotte E., Apr 27, 2014.

  1. Charlotte E.

    Charlotte E. Guest

    Does anyone know how to read/find the current users default browser via VBA?

    (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera
    Browser, etc...)

    I'm not talking about opening a website in the default browser, but finding
    out which browser the current user is using as the default one...

    I'm guessing it must be somewhere in the Registry, under HKEY_CURRENT_USER,
    since all users on the same computer are allowed to have their own choice of
    default browser - but where?

    A search on Google didn't help, but perhaps, I shouldn't get it from the
    Registry at all???

    So, how to tell which browser is the default one?


    TIA,

    CE



    ---
    Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret.
    http://www.avast.com
     
    Charlotte E., Apr 27, 2014
    #1
    1. Advertisements

  2. Charlotte E.

    isabelle Guest

    hi Charlotte,

    Sub CheckWebOptions()
    Dim wkbOne As Workbook
    Set wkbOne = Application.Workbooks(1)
    ' Determine the target browser.
    Select Case wkbOne.WebOptions.TargetBrowser
    Case msoTargetBrowserIE6: MsgBox "The target browser is IE6."
    Case msoTargetBrowserIE5: MsgBox "The target browser is IE5."
    Case msoTargetBrowserIE4: MsgBox "The target browser is IE4."
    Case msoTargetBrowserV4: MsgBox "Microsoft Internet Explorer 4.0, Netscape
    Navigator 4.0."
    Case msoTargetBrowserV3: MsgBox "Microsoft Internet Explorer 3.0, Netscape
    Navigator 3.0."
    Case Else: MsgBox "The target browser is not in the given list"
    End Select
    End Sub

    isabelle

    Le 2014-04-27 08:18, Charlotte E. a écrit :
    > Does anyone know how to read/find the current users default browser via VBA?
    >
    > (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera
    > Browser, etc...)
    >
    > I'm not talking about opening a website in the default browser, but finding
    > out which browser the current user is using as the default one...
    >
    > I'm guessing it must be somewhere in the Registry, under HKEY_CURRENT_USER,
    > since all users on the same computer are allowed to have their own choice of
    > default browser - but where?
    >
    > A search on Google didn't help, but perhaps, I shouldn't get it from the
    > Registry at all???
    >
    > So, how to tell which browser is the default one?
    >
    >
    > TIA,
    >
    > CE
    >
    >
    >
    > ---
    > Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret.
    > http://www.avast.com
    >
     
    isabelle, Apr 27, 2014
    #2
    1. Advertisements

  3. Charlotte E.

    isabelle Guest

  4. Charlotte E.

    Charlotte E. Guest

    Thanks, Isabelle, but it doesn't tell me, if it is Chrome, Firefox, Safari,
    or another browser, but only support IE...

    ....and, since Windows know the default browser, it must be possible to get
    it in VBA also.

    (I did know about that one - as I said, I've already looked around the net
    myself)

    Thanks for your effort anyway :)

    CE


    "isabelle" <> wrote in message news:ljj54l$7e5$...
    > hi Charlotte,
    >
    > Sub CheckWebOptions()
    > Dim wkbOne As Workbook
    > Set wkbOne = Application.Workbooks(1)
    > ' Determine the target browser.
    > Select Case wkbOne.WebOptions.TargetBrowser
    > Case msoTargetBrowserIE6: MsgBox "The target browser is IE6."
    > Case msoTargetBrowserIE5: MsgBox "The target browser is IE5."
    > Case msoTargetBrowserIE4: MsgBox "The target browser is IE4."
    > Case msoTargetBrowserV4: MsgBox "Microsoft Internet Explorer 4.0,
    > Netscape Navigator 4.0."
    > Case msoTargetBrowserV3: MsgBox "Microsoft Internet Explorer 3.0,
    > Netscape Navigator 3.0."
    > Case Else: MsgBox "The target browser is not in the given list"
    > End Select
    > End Sub
    >
    > isabelle
    >
    > Le 2014-04-27 08:18, Charlotte E. a écrit :
    >> Does anyone know how to read/find the current users default browser via
    >> VBA?
    >>
    >> (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera
    >> Browser, etc...)
    >>
    >> I'm not talking about opening a website in the default browser, but
    >> finding
    >> out which browser the current user is using as the default one...
    >>
    >> I'm guessing it must be somewhere in the Registry, under
    >> HKEY_CURRENT_USER,
    >> since all users on the same computer are allowed to have their own choice
    >> of
    >> default browser - but where?
    >>
    >> A search on Google didn't help, but perhaps, I shouldn't get it from the
    >> Registry at all???
    >>
    >> So, how to tell which browser is the default one?
    >>
    >>
    >> TIA,
    >>
    >> CE
    >>
    >>
    >>
    >> ---
    >> Denne e-mail er fri for virus og malware fordi avast! Antivirus
    >> beskyttelse er aktiveret.
    >> http://www.avast.com
    >>




    ---
    Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelseer aktiveret.
    http://www.avast.com
     
    Charlotte E., Apr 27, 2014
    #4
  5. Charlotte E.

    Auric__ Guest

    Charlotte E. wrote:

    > Does anyone know how to read/find the current users default browser via
    > VBA?
    >
    > (Internet Explorer, Google Chrome, Mozilla Firefox, Apple Safari, Opera
    > Browser, etc...)
    >
    > I'm not talking about opening a website in the default browser, but
    > finding out which browser the current user is using as the default
    > one...
    >
    > I'm guessing it must be somewhere in the Registry, under
    > HKEY_CURRENT_USER, since all users on the same computer are allowed to
    > have their own choice of default browser - but where?
    >
    > A search on Google didn't help, but perhaps, I shouldn't get it from the
    > Registry at all???
    >
    > So, how to tell which browser is the default one?


    Under Windows 7 & 8 (and probably Vista & 8.1):

    HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations
    \UrlAssociations\http\UserChoice\ProgID

    This points to an entry under HKEY_CLASSES_ROOT -- for example, in my Win8
    install, it's "IE.HTTP", while in my Win7 install it's "Opera.Protocol".

    Under Windows XP (and 2000, if you need to support it):

    HKEY_CURRENT_USER\Software\Classes\http\shell\open\command

    There's a different key used for what's listed on XP's start menu, but I
    don't remember what it is. Google should know, if you need it.

    Under Win9x & NT4 (if you need to support *those*):

    HKEY_CLASSES_ROOT\http\shell\open\command

    --
    In life, they were a motley crew: farmers, lords, cutpurses, priests.
    In death, they are united in a singular, benevolent purpose.
     
    Auric__, Apr 27, 2014
    #5
  6. Charlotte E.

    GS Guest

    Here's how I check to see what MSO apps are installed...

    Const sNames$ = "Internet Explorer,Firefox,Chrome"
    Dim oApp As Object, sz
    For Each sz In Split(sNames, ",")
    Set oApp = CreateObject(sz & ".Application")
    If Not oApp Is Nothing Then Beep: Exit For
    Next 'sz

    ...but that won't tell you the default browser. I'm curious why you need
    to know this because passing a URL in ShellExecute() opens in the
    user's default browser. I suppose you could do this and query its
    window title for the browser name, though!

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 28, 2014
    #6
  7. Charlotte E.

    Auric__ Guest

    GS wrote:

    > Here's how I check to see what MSO apps are installed...
    >
    > Const sNames$ = "Internet Explorer,Firefox,Chrome"
    > Dim oApp As Object, sz
    > For Each sz In Split(sNames, ",")
    > Set oApp = CreateObject(sz & ".Application")
    > If Not oApp Is Nothing Then Beep: Exit For
    > Next 'sz
    >
    > ..but that won't tell you the default browser. I'm curious why you need
    > to know this because passing a URL in ShellExecute() opens in the
    > user's default browser. I suppose you could do this and query its
    > window title for the browser name, though!


    Maybe documentation that was written differently for various browsers?

    --
    There are some prices that *nobody* should be willing to pay.
     
    Auric__, Apr 28, 2014
    #7
  8. Charlotte E.

    Peter T Guest

    > Does anyone know how to read/find the current users default browser via
    > VBA?


    Without reading the registry can use FindExecutable but it needs a file with
    an appropriate extension, simplified example

    ' adapt for 64bit office
    Private Declare Function FindExecutable Lib "shell32" _
    Alias "FindExecutableA" _
    (ByVal lpFile As String, _
    ByVal lpDirectory As String, _
    ByVal sResult As String) As Long

    Sub Test()
    Dim pos As Long
    Dim sExt As String
    Dim sFile As String
    Dim sPath As String
    Dim lReturn As Long
    Dim sResult As String

    sExt = "html"

    sPath = Application.DefaultFilePath & "\"
    sFile = DummyFile(sPath, sExt, True)
    If Len(sFile) = 0 Then
    ' problem creating file ?
    Else
    sResult = Space$(260)
    lReturn = FindExecutable(sFile, sPath, sResult)

    If lReturn >= 32 Then
    pos = InStr(sResult, Chr$(0))
    MsgBox Left$(sResult, pos - 1)
    Else
    MsgBox "Error code: " & lReturn
    End If
    End If

    DummyFile sPath, sExt, False

    End Sub

    Function DummyFile(sPath As String, sExt As String, bCreate As Boolean) As
    String
    Dim sFile As String
    Dim ff As Long

    sFile = sPath & "Dummy." & sExt
    On Error Resume Next
    Kill sFile
    On Error GoTo errExit

    ff = FreeFile
    Open sFile For Append As #ff
    Print #ff, "dummy file"
    Close #ff

    DummyFile = "Dummy." & sExt
    errExit:
    End Function

    Regards,
    Peter T
     
    Peter T, Apr 28, 2014
    #8
  9. Charlotte E.

    Charlotte E. Guest

    Awesome, Peter - it works :)

    And, not only does it tell you the browser, but also the full path to the
    browser...

    And, I've tested it with all five major browsers: Chrome, Firefox, MSIE,
    Opera and Safari..
    And, Opera and Safari, I even tried to install on some VERY unlikely
    loctions :)

    And, tested on both a Danish Windows 7, an English Windows XP, and even on a
    Windows Server OS :)
    And, it was tested on XL2003, XL2007, XL2010 and XL2013 - and, also in both
    Danish and English versions.

    So, not matter the browser, the installation, the Excel, the language or the
    OS - it just works :)


    Thanks, Peter - you saved my day :)


    CE





    "Peter T" <> wrote in message
    news:ljliu5$e5k$...
    >> Does anyone know how to read/find the current users default browser via
    >> VBA?

    >
    > Without reading the registry can use FindExecutable but it needs a file
    > with an appropriate extension, simplified example
    >
    > ' adapt for 64bit office
    > Private Declare Function FindExecutable Lib "shell32" _
    > Alias "FindExecutableA" _
    > (ByVal lpFile As String, _
    > ByVal lpDirectory As String, _
    > ByVal sResult As String) As Long
    >
    > Sub Test()
    > Dim pos As Long
    > Dim sExt As String
    > Dim sFile As String
    > Dim sPath As String
    > Dim lReturn As Long
    > Dim sResult As String
    >
    > sExt = "html"
    >
    > sPath = Application.DefaultFilePath & "\"
    > sFile = DummyFile(sPath, sExt, True)
    > If Len(sFile) = 0 Then
    > ' problem creating file ?
    > Else
    > sResult = Space$(260)
    > lReturn = FindExecutable(sFile, sPath, sResult)
    >
    > If lReturn >= 32 Then
    > pos = InStr(sResult, Chr$(0))
    > MsgBox Left$(sResult, pos - 1)
    > Else
    > MsgBox "Error code: " & lReturn
    > End If
    > End If
    >
    > DummyFile sPath, sExt, False
    >
    > End Sub
    >
    > Function DummyFile(sPath As String, sExt As String, bCreate As Boolean) As
    > String
    > Dim sFile As String
    > Dim ff As Long
    >
    > sFile = sPath & "Dummy." & sExt
    > On Error Resume Next
    > Kill sFile
    > On Error GoTo errExit
    >
    > ff = FreeFile
    > Open sFile For Append As #ff
    > Print #ff, "dummy file"
    > Close #ff
    >
    > DummyFile = "Dummy." & sExt
    > errExit:
    > End Function
    >
    > Regards,
    > Peter T
    >




    ---
    This email is free from viruses and malware because avast! Antivirus protection is active.
    http://www.avast.com


    ---
    Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret.
    http://www.avast.com
     
    Charlotte E., Apr 29, 2014
    #9
  10. Charlotte E.

    Peter T Guest

    "Charlotte E." <> wrote in message
    > Awesome, Peter - it works :)



    Glad it works but just seen a stupid omission in the DummyFile routine. Add
    the If bCreate pair. Whole point of course being to delete the file when
    done, not recreate it again!


    Function DummyFile(sPath As String, sExt As String, bCreate As Boolean) As
    String
    Dim sFile As String
    Dim ff As Long

    sFile = sPath & "Dummy." & sExt
    On Error Resume Next
    Kill sFile
    On Error GoTo errExit

    If bCreate Then
    ff = FreeFile
    Open sFile For Append As #ff
    Print #ff, "dummy file"
    Close #ff
    End If

    DummyFile = "Dummy." & sExt

    errExit:
    End Function
     
    Peter T, Apr 29, 2014
    #10
  11. Charlotte E.

    GS Guest

    > "Charlotte E." <> wrote in message
    >> Awesome, Peter - it works :)

    >
    >
    > Glad it works but just seen a stupid omission in the DummyFile
    > routine. Add the If bCreate pair. Whole point of course being to
    > delete the file when done, not recreate it again!
    >
    >
    > Function DummyFile(sPath As String, sExt As String, bCreate As
    > Boolean) As String
    > Dim sFile As String
    > Dim ff As Long
    >
    > sFile = sPath & "Dummy." & sExt
    > On Error Resume Next
    > Kill sFile
    > On Error GoTo errExit
    >
    > If bCreate Then
    > ff = FreeFile
    > Open sFile For Append As #ff
    > Print #ff, "dummy file"
    > Close #ff
    > End If
    >
    > DummyFile = "Dummy." & sExt
    >
    > errExit:
    > End Function


    I was going to suggest same, but thinking this function isn't really
    necessary if you have a list of executable filenames!<g>

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 29, 2014
    #11
  12. Charlotte E.

    GS Guest

    Nice!

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 29, 2014
    #12
  13. Charlotte E.

    GS Guest

    > but thinking this function isn't really necessary if you have a list
    > of executable filenames


    Uh.., I stand corrected if one doesn't already have a procedure for
    creating files! Since I already have this the 'Kill' statement would be
    included in the 'GetExecutable$()' function so it runs stand-alone and
    callable to return the info.

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 29, 2014
    #13
  14. Charlotte E.

    Peter T Guest

    "GS" <> wrote in message
    >> but thinking this function isn't really necessary if you have a list of
    >> executable filenames

    >
    > Uh.., I stand corrected if one doesn't already have a procedure for
    > creating files! Since I already have this the 'Kill' statement would be
    > included in the 'GetExecutable$()' function so it runs stand-alone and
    > callable to return the info.


    Gary, not sure I follow but what I posted was only intended as example,
    adapt as required, typically as a function to receive an extension and
    return the exe name possibly with its path. If you know the location of a
    file with the extension no need to make a dummy, or maybe adapt to create a
    dummy optionally if a known *.ext doesn't exist (and kill it of course!).
    All in the one function or two as I posted is only style.

    Charlotte, although it's worked 100% in your testing it can fail, not least
    if there is no file association (though unlikely not to have a default
    browser). Return values 1 to 31 are error codes to inform what the problem
    was and there's a list out there somewhere if you search FindExecutable.
    Don't forget to adapt for 64bit if necessary including the return var as
    LongPtr.

    You didn't say what the objective was but if to launch the default browser
    with a given file simply use ShellExecute.

    Regards,
    Peter T
     
    Peter T, Apr 29, 2014
    #14
  15. Charlotte E.

    GS Guest

    > Gary, not sure I follow but what I posted was only intended as
    > example, adapt as required, typically as a function to receive an
    > extension and return the exe name possibly with its path. If you know
    > the location of a file with the extension no need to make a dummy, or
    > maybe adapt to create a dummy optionally if a known *.ext doesn't
    > exist (and kill it of course!). All in the one function or two as I
    > posted is only style.


    Thanks, Peter! I got that after realizing not everyone has file I/O
    wrappers as I have. In the interest of keeping the procedure 'generic',
    though, it's clearly better to use a temp dummy file as you exampled,
    IMO.

    Nice utility to have in my "mFunctions.bas". Thanks for sharing it!!!

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 29, 2014
    #15
  16. Charlotte E.

    Charlotte E. Guest

    Hi Peter,

    > although it's worked 100% in your testing it can fail, if there is no file
    > association


    I know, and I've already adapted the function to take this into
    consideration :)

    The purpose for the function is in connection with working with IE
    Automation, if you use IE as hidden during the process.
    Sometimes, if the IE automation fails, IE might not get closed properly, and
    you can end up having a number of IE process running in the background, with
    no purpose, taking up resources.
    So, I've made a little macro, which kills all running IE processes.
    BUT! I don't want to kill all running IE processes, if IE is the default
    browser, because then I might kill an open IE window, which the user has
    opended on purpose, and want to keep open - thus, the need to know the
    default browser of the system.

    PS: And, the function also works with Avant Browser :)

    Once, angin, thank you for your help and effort...

    CE



    "Peter T" <> wrote in message
    news:ljp3mf$e5p$...
    >
    > "GS" <> wrote in message
    >>> but thinking this function isn't really necessary if you have a list of
    >>> executable filenames

    >>
    >> Uh.., I stand corrected if one doesn't already have a procedure for
    >> creating files! Since I already have this the 'Kill' statement would be
    >> included in the 'GetExecutable$()' function so it runs stand-alone and
    >> callable to return the info.

    >
    > Gary, not sure I follow but what I posted was only intended as example,
    > adapt as required, typically as a function to receive an extension and
    > return the exe name possibly with its path. If you know the location of a
    > file with the extension no need to make a dummy, or maybe adapt to create
    > a dummy optionally if a known *.ext doesn't exist (and kill it of
    > course!). All in the one function or two as I posted is only style.
    >
    > Charlotte, although it's worked 100% in your testing it can fail, not
    > least if there is no file association (though unlikely not to have a
    > default browser). Return values 1 to 31 are error codes to inform what the
    > problem was and there's a list out there somewhere if you search
    > FindExecutable. Don't forget to adapt for 64bit if necessary including the
    > return var as LongPtr.
    >
    > You didn't say what the objective was but if to launch the default browser
    > with a given file simply use ShellExecute.
    >
    > Regards,
    > Peter T
    >




    ---
    This email is free from viruses and malware because avast! Antivirus protection is active.
    http://www.avast.com


    ---
    Denne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret.
    http://www.avast.com
     
    Charlotte E., Apr 30, 2014
    #16
  17. Charlotte E.

    GS Guest

    You can set a fully qualified object ref to your CreateObject()
    instance so you never have to worry about other running instances. You
    can even make it run 'like' it's an in-process app extension so it
    closes automatically when your app closes. I do this for my apps that
    use a html.exe as a userguide. My app tracks any running instance it
    creates via its hwnd to ensure there's only 1 instance being used
    whether it's already running or not. Very easy to do with any EXE,
    really!<g>

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 30, 2014
    #17
  18. Charlotte E.

    Peter T Guest

    "GS" <> wrote in message
    > You can set a fully qualified object ref to your CreateObject() instance
    > so you never have to worry about other running instances. You can even
    > make it run 'like' it's an in-process app extension so it closes
    > automatically when your app closes. I do this for my apps that use a
    > html.exe as a userguide. My app tracks any running instance it creates via
    > its hwnd to ensure there's only 1 instance being used whether it's already
    > running or not. Very easy to do with any EXE, really!<g>


    For html.exe probably best to close it (if open) with the help api, first
    HH_CLOSE_ALL and then HH_UNINITIALIZE (the latter should be done anyway even
    if not currently open but if earlier initialized)

    Regards,
    Peter T
     
    Peter T, Apr 30, 2014
    #18
  19. Charlotte E.

    GS Guest

    > For html.exe probably best to close it (if open) with the help api,
    > first HH_CLOSE_ALL and then HH_UNINITIALIZE (the latter should be
    > done anyway even if not currently open but if earlier initialized)


    Not sure you understand me. I have created a pure VB wrapper that
    allows me to manage my stand-alone EXE user guide 'as though' it was a
    CHM running 'in-process'. It does not use the help API, but does use
    the following API functions...

    from user32.dll:
    EnumWindows
    GetClassName
    GetWindowText
    ShowWindow
    SetForegroundWindow
    IsIconic
    IsWindowVisible
    SendMessage

    from shell32.dll:
    ShellExecute

    ...to keep track of the EXE it's managing. All that's required to use it
    is the full filename of the EXE!

    --
    Garry

    Free usenet access at http://www.eternal-september.org
    Classic VB Users Regroup!
    comp.lang.basic.visual.misc
    microsoft.public.vb.general.discussion
     
    GS, Apr 30, 2014
    #19
    1. Advertisements

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Carole
    Replies:
    0
    Views:
    139
    Carole
    Jul 8, 2003
  2. brianelson

    Close Browser window with VBA

    brianelson, Jul 12, 2003, in forum: Excel Programming
    Replies:
    1
    Views:
    137
    Orlando Magalhães Filho
    Jul 12, 2003
  3. Tom
    Replies:
    0
    Views:
    107
  4. Ken Hunter
    Replies:
    2
    Views:
    201
    Jim Vita
    Jul 31, 2003
  5. Ted Theodoropoulos

    Running macro in a browser window

    Ted Theodoropoulos, Aug 4, 2003, in forum: Excel Programming
    Replies:
    1
    Views:
    81
    Greg Griffiths
    Aug 4, 2003
  6. Default browser for web querys?

    , Feb 9, 2005, in forum: Excel Programming
    Replies:
    0
    Views:
    83
  7. Andrew

    Change Default Hyperlink Browser..?

    Andrew, Apr 6, 2010, in forum: Excel Programming
    Replies:
    1
    Views:
    97
  8. ryguy7272
    Replies:
    11
    Views:
    449
    Mike S
    Aug 6, 2010
Loading...