Frage

Welche RegKey können Sie die Standard-Browser-Anwendung Pfad her?

Der beste Weg, um es von C # bekommen /. NET?

War es hilfreich?

Lösung

Hier ist der Schlüssel Sie möchten:

  

HKEY_LOCAL_MACHINE \ Software \ Classes \ http \ shell \ open \ command

Und hier ist eine schnelle Registrierung Tutorial für C # , wenn Sie es brauchen.

Bearbeiten :

Für pro-Benutzer-Einstellungen, verwenden Sie diese Taste:

  

HKEY_CLASSES_ROOT \ http \ shell \ open \ command

(HKCR beide Maschine und Benutzereinstellungen hat, Benutzer hat Priorität).

Beachten Sie, dass dies nicht auf Vista funktionieren könnte . Für mehr Informationen, siehe hier .

Andere Tipps

für Windows 7 Standard-Browser Pfad speichern in den folgenden Registrierungsschlüssel

 HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http

von c # verwenden Sie können es wie folgt -

RegistryKey regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false);

string browser = regkey.GetValue("Progid").ToString();

Auf der Grundlage Ihrer Antworten schrieb ich diesen Beispielcode, tun sollten, was Sie wollen (nicht getestet)

public static string GetDefaultBrowserPath()
    {
        string defaultBrowserPath = null;
        RegistryKey regkey;

        // Check if we are on Vista or Higher
        OperatingSystem OS = Environment.OSVersion;
        if ((OS.Platform == PlatformID.Win32NT) && (OS.Version.Major >= 6))
        {
            regkey = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\shell\\Associations\\UrlAssociations\\http\\UserChoice", false);
            if (regkey != null)
            {
                defaultBrowserPath = regkey.GetValue("Progid").ToString();
            }
            else
            {
                regkey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Classes\\IE.HTTP\\shell\\open\\command", false);
                defaultBrowserPath = regkey.GetValue("").ToString();
            }
        }
        else
        {
            regkey = Registry.ClassesRoot.OpenSubKey("http\\shell\\open\\command", false);
            defaultBrowserPath = regkey.GetValue("").ToString();
        }

        return defaultBrowserPath;
    }

Ich habe gerade eine Funktion dafür:

    public void launchBrowser(string url)
    {
        string browserName = "iexplore.exe";
        using (RegistryKey userChoiceKey = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"))
        {
            if (userChoiceKey != null)
            {
                object progIdValue = userChoiceKey.GetValue("Progid");
                if (progIdValue != null)
                {
                    if(progIdValue.ToString().ToLower().Contains("chrome"))
                        browserName = "chrome.exe";
                    else if(progIdValue.ToString().ToLower().Contains("firefox"))
                        browserName = "firefox.exe";
                    else if (progIdValue.ToString().ToLower().Contains("safari"))
                        browserName = "safari.exe";
                    else if (progIdValue.ToString().ToLower().Contains("opera"))
                        browserName = "opera.exe";
                }
            }
        }

        Process.Start(new ProcessStartInfo(browserName, url));
    }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top