Pergunta

O que RegKey você pode obter o caminho do aplicativo navegador padrão de?

A melhor maneira de chegar a ele a partir de C # /. NET?

Foi útil?

Solução

Aqui está a chave que você deseja:

HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ http \ shell \ open \ command

E aqui está uma rápida registro tutorial para C # , se você precisar dele.

Editar :

Para configurações por usuário, use esta chave:

HKEY_CLASSES_ROOT \ http \ shell \ open \ command

(HKCR tem tanto máquina e de usuário configurações, o usuário tem prioridade).

Nota que este pode não funcionar em Vista . Para mais informações, veja aqui .

Outras dicas

para o caminho navegador windows 7 padrão de salvamento na seguinte chave do Registro

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

usando c # você pode obtê-lo da seguinte forma -

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

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

Com base em suas respostas Eu escrevi este código de exemplo que deve fazer o que quiser (não testado)

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;
    }

Eu só fiz uma função para isso:

    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));
    }
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top