Results 1 to 12 of 12

Thread: check the default browser

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    check the default browser

    Hi there,
    how will i check a default browser?

    i will open a site and i will opened it in IE only.so, i need to check first if the default browser is IE.if not,then i will open it in IE..if IE is not available then i will show a message that IE is not installed in your computer..

    also,if IE is already opened then i will launch the website on the next tab in IE browser...

    i used process.start("iexplorer.exe",website) and it will create new instance of IE everytime i open a site..

    thank you..

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: check the default browser

    Well when you start a website you are using "http". So how does Windows know what program to associate with this class? If you navigate in your registry to:

    Code:
    HKEY_CLASSES_ROOT\http\shell\open\command
    You will see the default command line that is run, along with which program will run it. For me I get:

    Code:
    "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -requestPending -osint -url "%1"
    So... Firefox is going to handle my requests for http. You can use the managed registry classes that the .NET framework provides to check these settings.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: check the default browser

    Quote Originally Posted by ForumAccount View Post
    Well when you start a website you are using "http". So how does Windows know what program to associate with this class? If you navigate in your registry to:

    Code:
    HKEY_CLASSES_ROOT\http\shell\open\command
    hi, i cannot see "http" under HKEY_CLASSES_ROOT in my registry..

  4. #4
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: check the default browser

    Quote Originally Posted by [gja] View Post
    hi, i cannot see "http" under HKEY_CLASSES_ROOT in my registry..
    Try:
    HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice
    Under that key, you should see a value name Progid. If IE is set to default, you should see IE.HTTP in it. I only tested it on IE9, but I can't imagine there's a difference in older versions of IE.

    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: check the default browser

    HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice
    hello,i cannot see "Associations" under Shell folder..its BagMRU and Bags folders under a shell folder.

  6. #6
    Wait... what? weirddemon's Avatar
    Join Date
    Jan 2009
    Location
    USA
    Posts
    3,826

    Re: check the default browser

    Quote Originally Posted by [gja] View Post
    hello,i cannot see "Associations" under Shell folder..its BagMRU and Bags folders under a shell folder.
    What OS are you using?

    Also, you can use ProcMon to latch onto the iexpore.exe process and see what key it is writing to when it sets the default.

    Instead of just taking our suggestions and saying, "it doesn't work" you need to do some leg work on your own.
    CodeBank contributions: Process Manager, Temp File Cleaner

    Quote Originally Posted by SJWhiteley
    "game trainer" is the same as calling the act of robbing a bank "wealth redistribution"....

  7. #7
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: check the default browser

    The following additions to My.Computer should assist (not tested under Windows 7)

    InternetExplorerInstalled()
    Determines if Internet Explorer is installed

    InternetExplorerRunCommand()
    Returns the run command for Internet Explorer

    InternetExplorerExecutable()
    Path and file name for MS-Internet Explorer

    DefaultWebBrowser
    Get the default web browser


    Example
    Code:
    Console.WriteLine("Default browser [{0}]", My.Computer.DefaultWebBrowser)
    If My.Computer.InternetExplorerInstalled Then
        Console.WriteLine("IE executable [{0}]", My.Computer.InternetExplorerExecutable)
        Console.WriteLine("Run command [{0}]", My.Computer.InternetExplorerRunCommand(False))
    Else
        Console.WriteLine("Microsoft Internet Explorer not installed")
    End If

    Output for my computer
    Code:
    Default browser ["C:\Program Files\Internet Explorer\iexplore.exe"]
    IE executable [C:\Program Files\Internet Explorer\IEXPLORE.EXE]
    [C:\Program Files\Internet Explorer\iexplore.exe ]
    ["C:\Program Files\Internet Explorer\iexplore.exe" %1]

    Add the attached file to your project
    Last edited by kareninstructor; Apr 16th, 2011 at 09:15 AM.

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: check the default browser

    Hello kevin,thank you for your reply.

    i used your class like this..


    Code:
     Try
                If My.Computer.InternetExplorerInstalled Then
                    System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
                Else
                    MessageBox.Show("Microsoft Internet Explorer not installed")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Try

    do you have any advice, if internet explorer is already opened it will not create new instance of it,rather, it will add new tab on existing IE instance?..

  9. #9
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: check the default browser

    Quote Originally Posted by [gja] View Post
    Hello kevin,thank you for your reply.

    i used your class like this..


    Code:
     Try
                If My.Computer.InternetExplorerInstalled Then
                    System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
                Else
                    MessageBox.Show("Microsoft Internet Explorer not installed")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Try

    do you have any advice, if internet explorer is already opened it will not create new instance of it,rather, it will add new tab on existing IE instance?..

    See comments within the code below.

    Code:
            If My.Computer.InternetExplorerInstalled Then
                If My.Computer.IsInternetExplorerRunning Then
                    ' starting a page should open in the current instance of IE
                Else
                    ' new instance of IE will be started
                End If
            Else
                MessageBox.Show("Microsoft Internet Explorer not installed")
            End If
    Place the following code in the code module I uploaded
    Code:
            Public Function IsInternetExplorerRunning() As Boolean
    
                Dim query = (From p In System.Diagnostics.Process.GetProcesses() _
                             Where p.ProcessName = "iexplore").FirstOrDefault
    
                If query IsNot Nothing Then
                    Return True
                Else
                    Return False
                End If
            End Function

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: check the default browser

    Hi kevin.

    this is what i have now..

    Code:
     Try
                If My.Computer.InternetExplorerInstalled Then
                    If My.Computer.IsInternetExplorerRunning Then
                        ' starting a page should open in the current instance of IE
                        System.Diagnostics.Process.Start(TextBox1.Text.Trim)
                    Else
                        ' new instance of IE will be started
                        System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
                    End If
                Else
                    MessageBox.Show("Microsoft Internet Explorer not installed")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Try
    i dont know how to open another site in a new tab...highlighted text above work only if IE is my default browser but my default browser is FF...

  11. #11
    Karen Payne MVP kareninstructor's Avatar
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    6,713

    Re: check the default browser

    Quote Originally Posted by [gja] View Post
    Hi kevin.

    this is what i have now..

    Code:
     Try
                If My.Computer.InternetExplorerInstalled Then
                    If My.Computer.IsInternetExplorerRunning Then
                        ' starting a page should open in the current instance of IE
                        System.Diagnostics.Process.Start(TextBox1.Text.Trim)
                    Else
                        ' new instance of IE will be started
                        System.Diagnostics.Process.Start(My.Computer.InternetExplorerExecutable, TextBox1.Text.Trim)
                    End If
                Else
                    MessageBox.Show("Microsoft Internet Explorer not installed")
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message, "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning)
            End Try
    i dont know how to open another site in a new tab...highlighted text above work only if IE is my default browser but my default browser is FF...
    Since I do not have FF I do not have an answer for you.

  12. #12
    New Member
    Join Date
    Feb 2011
    Posts
    5

    Resolved Re: check the default browser

    Hi. I'm usually a new member here. I know there is a way to get if Firefox is your default browser or other browsers..

    Its not http for getting the default browser. but it's the ".htm" extension you should check.

    How did I find out?
    I've tested changing "FirefoxHTML" into another string that is not for firefox then I started running firefox.
    When it opens, it says that firefox is not your default browser.


    So here is the code that I wrote:
    Code:
        Public Function GetDefaultBrowser() As String
            Dim GetLink As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\.htm", "", "")
            'Gets the default value of the .htm extension for locating the default browser's parameter
    
            Dim Result As String = My.Computer.Registry.GetValue("HKEY_CLASSES_ROOT\" + GetLink + "\shell\open\command", "", "")
            'Gets the shell command of the default browser to be returned.
            Return Result.ToString
        End Function
    So if your default browser is firefox, then it will appear the code below
    Code:
    "C:\Program Files (x86)\Mozilla Firefox\firefox.exe" -requestPending -osint -url "%1"
    If you want to browse something, then just replace "%1" to the web you like.

    Example:
    Code:
            Dim WebLocation As String = GetDefaultBrowser.Replace("%1", "vbforums.com")
            Shell(WebLocation)
            'Replace vbforums.com to any location in the web to be launched by the default browser.
    I hope this helped you [gja].

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width