Is there a way of detecting whether a url handler exists for a particular protocol?

On macOS and Windows, is there anything in either Xojo or MBS plugins that can tell me whether an app has been configured to handle a particular URL protocol? I don’t need to know which app, just whether anything will handle a particular type of URL.

It’s certainly possible on macOS:

https://developer.apple.com/documentation/foundation/nsurlconnection/1413072-canhandlerequest/

Which means it’s almost certain that MBS has a command.

Thanks, Greg! Yes, something like that would work well, and if there’s an equivalent on Windows then even better.

@Christian_Schmitz Do you have anything that covers this?

Maybe this one?

LaunchServicesAllHandlersForURLSchemeMBS(URLScheme as string) as LaunchServicesStringListMBS

For Windows:

Private Function GetRegisteredURLProtocols() As Dictionary

  // Walking the Windows registry in Xojo seems very costly
  // it takes many seconds to read all classes
  // Be patient while selecting and caching the list of handlers
  
  Var registeredURLProtocols As New Dictionary
  Var reg As New RegistryItem("HKEY_CLASSES_ROOT", False)
  
  Var curItem As Integer = 0
  
  Do
    
    Try
      Var inspect As RegistryItem = reg.Item(curItem)
      
      Try
        Var isURLProtocol As Variant = inspect.Value("URL Protocol")
        If isURLProtocol<>Nil then 
          var name As String = inspect.Path.Middle(18) // Remove "HKEY_CLASSES_ROOT\"
          registeredURLProtocols.Value(name)=inspect.DefaultValue.StringValue
        End
      Catch RegistryAccessErrorException // Doesn't exist
      End
      
    Catch RegistryAccessErrorException // End of list
      Exit
    End
    
    curItem = curItem + 1
    
  Loop
  
  Return registeredURLProtocols
  
End Function
1 Like

Thanks to both @Christian_Schmitz and @Rick_Araujo for the helpful answers!

1 Like