Feedback

Eigenes URL-Protokoll registrieren

+ „“““ %1″“);

// using Microsoft.Win32; nicht vergessen!

/// <summary>
/// Registriert ein benutzerdefiniertes URL-Protokoll für die Verwendung mit der
/// Windows-Shell, dem Internet Explorer und Office.
/// 
/// Beispiel für einen URL eines benutzerdefinierten URL-Protokolls:
/// 
///   rainbird://RemoteControl/OpenFridge/GetBeer
/// </summary>
/// <param name="protocolName">Name des Protokolls (z.B. "rainbird" für "rainbird://...")</param>
/// <param name="applicationPath">Vollständiger Dateisystem-Pfad zur EXE-Datei, die den URL bei Aufruf verarbeitet (Der komplette URL wird als Befehlszeilenparameter übergteben)</param>
/// <param name="description">Beschreibung (z.B. "URL:Rainbird Custom URL")</param>
public void RegisterURLProtocol(string protocolName, string applicationPath, string description)
{
    // Neuer Schlüssel für das gewünschte URL Protokoll erstellen
    RegistryKey myKey=Registry.ClassesRoot.CreateSubKey(protocolName);

    // Protokoll zuweisen
    myKey.SetValue(null, description);
    myKey.SetValue("URL Protocol", string.Empty);

    // Shellwerte eintragen
    Registry.ClassesRoot.CreateSubKey(protocolName + "\Shell");
    Registry.ClassesRoot.CreateSubKey(protocolName + "\Shell\open");
    myKey = Registry.ClassesRoot.CreateSubKey(protocolName + "\Shell\open\command");

    // Anwendung festlegen, die das URL-Protokoll behandelt
    myKey.SetValue(null, """ + applicationPath

3 Kommentare