WebBrowser as default

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jyoung2
    New Member
    • Jan 2008
    • 32

    WebBrowser as default

    I created a webrowser in VB.net to track employee usage and it seems to be working fine but I wanted to find out what it would take to set this as a default browser on a PC. I also would need to know how to pull the URL from shortcuts so when the program opens I can have it open to the URL in the shortcut.

    thank you
    John Young
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Here's what I do in C#. As you can see, the default browser is specified in the registry. You should be able to translate this to VB fairly easily.

    Code:
            
            private void pbLogo_Click(object sender, EventArgs e)
            {
                OpenURL(@"http://gallery.me.com/tlhintoq");
            }
    
    
    
            private static string GetDefaultBrowserPath()
            {
                string key = @"http\shell\open\command";
                Microsoft.Win32.RegistryKey registryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(key, false);
                // get default browser path
                return StringToPath(((string)registryKey.GetValue(null, null)));
            }
    
    
    
            void OpenURL(string TheURL)
            {
                string defaultBrowserPath = GetDefaultBrowserPath();
    
                try
                {
                    // launch default browser
                    System.Diagnostics.Process.Start(defaultBrowserPath, TheURL);
                }
                catch (Exception exp)
                {
                    MessageBox.Show(exp.Message);
                }
            }

    Comment

    • jyoung2
      New Member
      • Jan 2008
      • 32

      #3
      What I am trying to do is set the webbrowser I created to the default browser. I am not looking for the current default I am trying to change it.

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        If you know where that value is stored, you can write in a new value. Hence, change it.

        Write a new value that contains the path to your custom browser.

        Comment

        • jyoung2
          New Member
          • Jan 2008
          • 32

          #5
          I found where to change it, It is getting an error because it is not handeling URI Formats "System.Argumen tException: URI formats are not supported." So i am going to work though and see if I can work around this. If you have an idea of where to start that would be great, otherwise I will fight through it until I can form a coherent question, ;-) and try again. thanks!

          Comment

          • tlhintoq
            Recognized Expert Specialist
            • Mar 2008
            • 3532

            #6
            Originally posted by jyoung2
            I found where to change it, It is getting an error because it is not handeling URI Formats "System.Argumen tException: URI formats are not supported." So i am going to work though and see if I can work around this. If you have an idea of where to start that would be great, otherwise I will fight through it until I can form a coherent question, ;-) and try again. thanks!
            Breakpoints are your friend. Set a breakpoint so you can see exactly what is being sent to the OpenURL method.

            If I recall, you can send literals to the method if you put quotes around the entire string. If you don't use quotes then you have to translate characters such as spaces to %20 and so on.

            Comment

            • jyoung2
              New Member
              • Jan 2008
              • 32

              #7
              My Current Hiccup is that i only recive the error when I open a link when my program is closed and when it opens the program it skips the break points. I am unsure how to get the program to open in debug mode. I am trying to figure out the information that is getting sent the program when it is opening so I can handle it.
              In the debug folder is there a file that will open in debug mode when opened from outside of Visual Studio?

              Comment

              • tlhintoq
                Recognized Expert Specialist
                • Mar 2008
                • 3532

                #8
                Can't say as I've ever tried it.
                I would have expected that if you already had it running in debug mode from Visual Studio, and your registry entry was pointing at the debug version of the application (the one in the debug folder) that it would pass it to the instance already open. But as I said, I've never tried it.

                Comment

                Working...