public bool Unregister(ProtocolRegistryScope scope, string scheme) { if (Exists(scheme)) { try { Walk( Registry.ClassesRoot, new [] { scheme, }, subKey => Registry.ClassesRoot.DeleteSubKeyTree(scheme // TODO: This should not be here /*, false*/)); // TODO: Fix this? Is this some CE compatibility // or something we aren’t cleaning up we should // clean up? /* * Walk( * Registry.ClassesRoot, * new [] { * scheme, * }, * subKey => { * }); */ } catch (UnauthorizedAccessException ex) { Console.Error.WriteLine(ex); return(Elevate(false, scheme)); } } if (!disablePrivilegeEscalation) { // Privilege escalation will happen in the future, so // say we succeeded even though we didn’t and only // actually fail if we’re already in the escalation // round. return(true); } return(!Exists(scheme)); }
/// <summary> /// Unregister a protocol handler. /// </summary> /// <returns>true if, as far as the system can determine, the protocol is no longer registered.</returns> public bool Unregister(ProtocolRegistryScope scope, string scheme) { return(ForEachProtocolRegistrar(true, protocolRegistrar => protocolRegistrar.Unregister(scope, scheme))); }
/// <summary> /// Register a protocol handler. /// </summary> /// <returns>true on success.</returns> public bool Register(ProtocolRegistryScope scope, string scheme, string applicationPath) { return(ForEachProtocolRegistrar(false, protocolRegistrar => protocolRegistrar.Register(scope, scheme, applicationPath))); }
public bool Register(ProtocolRegistryScope scope, string scheme, string applicationPath) { Exception thrownException; try { Console.Error.WriteLine("A"); // On Windows CE, the Classes key will only be // searched for our protocol if we create the key // HKLM\SOFTWARE\Microsoft\Shell\URLProtocols\<proto> // as described at // http://thegrayzone.co.uk/blog/2010/08/custom-url-protocol-in-windows-ce/ // linked by // http://stackoverflow.com/a/4108720/429091. We can // detect this situation by TODO: BY DOING WHAT?! Console.Error.WriteLine("B"); Walk( Registry.ClassesRoot, new [] { scheme, }, subKey => { subKey.SetValue("URL Protocol", "", RegistryValueKind.String); Walk( subKey, new [] { "DefaultIcon", }, defaultIconKey => defaultIconKey.SetValue(null, applicationPath + ", 0", RegistryValueKind.String), true); Walk( subKey, new [] { "shell", "open", "command", }, commandKey => commandKey.SetValue(null, applicationPath + " \"%1\"", RegistryValueKind.String), true); }, true); Console.Error.WriteLine("C"); // To make the protocol show up in the Control Panel // GUI on Desktop Windows, it should be registered in // HKCU\SOFTWARE\Microsoft\Windows\Shell\Associations\UrlAssociations\<proto>. We // detect this situation by checking if the // UrlAssocations key exists. Walk() will quietly skip // when the key doesn’t exist. Walk( Registry.CurrentUser, new [] { "SOFTWARE", "Microsoft", "Windows", "Shell", "Associations", "UrlAssociations", }, urlAssociationsKey => Walk( urlAssociationsKey, new [] { scheme, }, subKey => Console.Error.WriteLine("Ensured UrlAssociations/{0} exists.", scheme), create: true)); return(true); } catch (UnauthorizedAccessException ex) { thrownException = ex; } catch (SecurityException ex) { thrownException = ex; } // Just let it pass for now, by failing out will get // to ElevateProtocolRegistrar. Console.Error.WriteLine(thrownException); return(Elevate(true, scheme, applicationPath)); }