0

I am writing a java application, which can handle standard links (http/https).

How can I register my application as the default program opening these links (aka default browser) in Windows 10?

I know I can select the default browser in the windows settings, but it only shows a limited list, no way to hook up a custom program.

I've found this, but it only shows how to do it pre-win10, plus I'm not sure it can be done in java.

F43nd1r
  • 7,690
  • 3
  • 24
  • 62
  • It looks like only Microsoft Store apps can be added to the default programs dropdown list. Still you can set programs to file types and protocols individually as shown in [this article](https://techforluddites.com/windows-10-change-the-default-programs-for-opening-files/). – Rashin May 06 '18 at 06:40
  • As @Rashin said I think you need to go throw the app store. Also, the link below shows how to build a custom browser (by Microsoft dev team) and they write the same there. https://blogs.windows.com/msedgedev/2015/08/27/creating-your-own-browser-with-html-and-javascript/ – Guy Grin May 06 '18 at 08:01
  • Doesn't this help in W10 https://stackoverflow.com/questions/32671277/how-do-i-register-a-custom-application-as-a-web-browser-in-windows-8-1 ? https://stackoverflow.com/questions/36865703/how-can-i-programatically-set-the-default-browser-in-windows-10 – Tarun Lalwani May 06 '18 at 08:42
  • @Rashin I don't think that is true, as firefox is part of that list and wasn't installed through the app store. – F43nd1r May 06 '18 at 11:10
  • @TarunLalwani that doesn't work on windows 10. (I just tested and confirmed it isn't working) – F43nd1r May 06 '18 at 14:14
  • Don't have windows 10 to confirm for you. Will see if I give something else – Tarun Lalwani May 06 '18 at 14:30
  • @TarunLalwani I figured it out. Windows 10 has some more restrictions, but the baseline is the same as in your first linked post (see my answer). Thanks! – F43nd1r May 06 '18 at 15:47
  • Glad it helped you in solving your issue :-) – Tarun Lalwani May 06 '18 at 16:49

1 Answers1

4
  1. The application needs to be packaged as an exe.

I used launch4j for this. Make sure textVersion and icon is set.

  1. A lot of registry keys need to be created. I've pieced those together by looking at this post (kindly linked by @Tarun Lalwani), this post, and the registry entries created by firefox. This means some of them might not be necessary.

Register client

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\Capabilities]
'ApplicationDescription'='MyApp'
'ApplicationIcon'='C:\MyApp\MyApp.exe,0'
'ApplicationName'='MyApp'

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\Capabilities\URLAssociations]
'http'='MyAppURL'
'https'='MyAppURL'

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\DefaultIcon]
@='C:\MyApp\MyApp.exe,0'

[HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\MyApp\shell\open\command]
@='C:\MyApp\MyApp.exe'

Register url handler

[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL]
@='MyApp Document'
'EditFlags'=0x2
'FriendlyTypeName'='MyApp Document'
'URL Protocol'=''

[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL\DefaultIcon]
@='C:\MyApp\MyApp.exe,0'

[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL\shell]
@='open'

[HKEY_LOCAL_MACHINE\Software\Classes\MyAppURL\shell\open\command]
@='"C:\MyApp\MyApp.exe" --url "%1"'

Register to default programs

[HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications]
'MyApp'='Software\Clients\StartMenuInternet\MyApp\Capabilities'
  1. Now the application can be selected in the windows settings
F43nd1r
  • 7,690
  • 3
  • 24
  • 62
  • would this work for any other type of program? Like not a browser, but something else that could open custom files? – Dahlin Jul 08 '22 at 20:53
  • @Dahlin this specifically registers the application as an url handler. For files I'd expect a similar approach to work, but the exact registry keys necessary are most likely different. – F43nd1r Jul 08 '22 at 21:46
  • oke thanks! But also, how would the registry keys be created, not via launch4j I guess? – Dahlin Jul 08 '22 at 21:56
  • @Dahlin I created them manually via regedit. Not sure how one would automate it, that would be another question. – F43nd1r Jul 09 '22 at 01:00
  • I have done that before, Advapi32 can do that for example, requires admin privileges though, I just thought there would be an easier way – Dahlin Jul 09 '22 at 07:44