Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Default Browser

Default Browser

Scheduled Pinned Locked Moved C#
windows-adminlinuxquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paul Riley
    wrote on last edited by
    #1

    I'm trying to launch the default browser, with a given URL in a particular event handler. The best I have so far is:

    using (RegistryKey rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\http\shell\open\command"))
    {
    	string val = rkey.GetValue(String.Empty).ToString();
    	string browser = val.Split('\"')[1];
    	Process.Start(browser, URL);
    }
    

    This works perfectly well on my machine but IE is the only browser I have installed, let alone the default. Can anyone tell me a) If there's a better place to look for the default browser and b) If Netscape, Opera, et al can be parsed out of that key using the same Split? Paul We all will feed the worms and trees
    So don't be shy
    - Queens of the Stone Age, Mosquito Song

    S D 2 Replies Last reply
    0
    • P Paul Riley

      I'm trying to launch the default browser, with a given URL in a particular event handler. The best I have so far is:

      using (RegistryKey rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\http\shell\open\command"))
      {
      	string val = rkey.GetValue(String.Empty).ToString();
      	string browser = val.Split('\"')[1];
      	Process.Start(browser, URL);
      }
      

      This works perfectly well on my machine but IE is the only browser I have installed, let alone the default. Can anyone tell me a) If there's a better place to look for the default browser and b) If Netscape, Opera, et al can be parsed out of that key using the same Split? Paul We all will feed the worms and trees
      So don't be shy
      - Queens of the Stone Age, Mosquito Song

      S Offline
      S Offline
      Stephane Rodriguez
      wrote on last edited by
      #2

      Key 1 : HKCR\.html ==> htmlfile Key 2 : HKCR\htmlfile\shell\open\command ==> "c:\....\iexplore.exe" | "...\netscape.exe" | "...."

      P 1 Reply Last reply
      0
      • P Paul Riley

        I'm trying to launch the default browser, with a given URL in a particular event handler. The best I have so far is:

        using (RegistryKey rkey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\http\shell\open\command"))
        {
        	string val = rkey.GetValue(String.Empty).ToString();
        	string browser = val.Split('\"')[1];
        	Process.Start(browser, URL);
        }
        

        This works perfectly well on my machine but IE is the only browser I have installed, let alone the default. Can anyone tell me a) If there's a better place to look for the default browser and b) If Netscape, Opera, et al can be parsed out of that key using the same Split? Paul We all will feed the worms and trees
        So don't be shy
        - Queens of the Stone Age, Mosquito Song

        D Offline
        D Offline
        Daniel Turini
        wrote on last edited by
        #3

        Just call Process.Start(URL) and it'll call the default browser for you.


        It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)

        P 1 Reply Last reply
        0
        • S Stephane Rodriguez

          Key 1 : HKCR\.html ==> htmlfile Key 2 : HKCR\htmlfile\shell\open\command ==> "c:\....\iexplore.exe" | "...\netscape.exe" | "...."

          P Offline
          P Offline
          Paul Riley
          wrote on last edited by
          #4

          I did think about using ".html" but I figured it was possible, if unlikely, that someone might have it set up so that double-clicking an .html file would open a different browser from the default. Daniel seems to have the perfect answer, but thanks anyway :) Paul We all will feed the worms and trees
          So don't be shy
          - Queens of the Stone Age, Mosquito Song

          1 Reply Last reply
          0
          • D Daniel Turini

            Just call Process.Start(URL) and it'll call the default browser for you.


            It's not the fall that kills you: it's the sudden stop - Down by Law, Jim Jamursch (1986)

            P Offline
            P Offline
            Paul Riley
            wrote on last edited by
            #5

            Nice answer Daniel. Didn't really give much thought to that idea, I didn't think it would work with a URL like "www.mydomain.com/mysite" (ie. no mention of http or html) but somehow it does. Very cool, thanks. Paul We all will feed the worms and trees
            So don't be shy
            - Queens of the Stone Age, Mosquito Song

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups