1

I have searched Google for URL Open Event for a long time, but Google just gives me inappropriate results...

Actually, I would like to know what happens when an application opens up an external URL.

For example, when someone sends you a link through Skype, you click the link and Skype will prompt you to IE/Chrome or other default browsers. I would like to know how to capture the event that opens up the browser. I do not want to set my application as default browser.

VB.net may have a limited function, if there is no way to achieve this, it is OK to give me a way of how to do it in C# or c++.

I absolutely have no idea on how to do this. Hope that someone can give me a hint :(


Add On: Maybe my question is not clear. What I need to do is not opening an URL. I would like to make an application to open up an URL through my application. For example, when I click the link on Skype. I want my application to grab the link that Skype was trying to open up instead of bring me up to a browser.

Eric Lam
  • 329
  • 1
  • 5
  • 13
  • If Google gives inappropriate results, it's the question that's inappropriate. There's no "URL Open Event". URLs are just data. Each application decides how to display and treat the text values it wants to treat as URLs. Most will do a `Process.Start` with the URL. Those that want to offer a choice, simply run the selected browser exe with the proper command line switches to open the URL. – Panagiotis Kanavos Jan 12 '15 at 07:54
  • Well, I am not trying to open an URL. I am trying to capture the event that an external application(e.g. Skype) opens an URL. I can feel that my question is inappropriate, but I'm not quite sure on how to describe that properly... – Eric Lam Jan 12 '15 at 08:27
  • There is no such event. It's just a `Process.Start` call for which the Windows Shell knows it needs to open a web browser – Panagiotis Kanavos Jan 12 '15 at 08:31
  • Oic. Then is there anyway to capture a Process.Start call? – Eric Lam Jan 12 '15 at 08:36
  • What is the real problem you are trying to solve? The question sounds like a case of [the XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) . If you want to handle a custom URL (eg like `git://` or `myapp://`) you can [register a protocol handler](http://msdn.microsoft.com/en-us/library/ie/aa767914(v=vs.85).aspx). That's how URI handling for `http`, `ftp` work. The OS will simply start the application you specify passing the URL as a parameter. All you need is a few registry keys – Panagiotis Kanavos Jan 12 '15 at 08:41
  • This seems like what I want to do now! Thanks for your answer :) – Eric Lam Jan 12 '15 at 09:01

1 Answers1

4

From the comments it seems the real question is "How can I have my application handle URL calls instead of the registered application"?

You can do that by registering your own protocol handler. Windows handles URIs through protocol handlers registered in the ... Registry. Every time a URL is entered in the Run box or started by Process.Start, the OS will check the registry to find a program registered for the URI's protocol. The OS will simply run the registered process passing the URL as a parameter

You can replace the http handler but you should be very careful, otherwise you can cause serious problems to your end users

  • You need to preserve the old values and revert to them when your application is removed
  • Installing a new browser or changing the default browser will also affect the handlers. This will break your handler. You may have to check for modifications periodically.
  • Users won't be very happy if you hijack all their URLs, cause browsing delays and displaying your UI. Your program should be very light and forward the URL to the previous handler (ie browser) if you don't want to handle it yourself.

Of course, if the reason you want to intercept URL calls is to provide your own prefix (like git:), you don't have to worry about any of this.

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
  • It seems like what I want to do now! I think it should be possible not to affect the end user if I add a handler just to open up a url pointing to a specific site? – Eric Lam Jan 12 '15 at 09:03