문제

기본 브라우저 애플리케이션의 경로를 어떤 regkey로 얻을 수 있습니까?

C#/. Net에서 얻는 가장 좋은 방법?

도움이 되었습니까?

해결책

원하는 키는 다음과 같습니다.

hkey_local_machine Software Classes http shell Open Command

그리고 여기에 빠릅니다 C#에 대한 레지스트리 튜토리얼, 필요한 경우.

편집하다:

사용자 당 설정의 경우이 키를 사용하십시오.

hkey_classes_root http shell open 명령

(HKCR에는 기계와 사용자 설정이 모두 있으며 사용자는 우선 순위를 갖습니다).

이것은 Vista에서 작동하지 않을 수 있습니다. 더 많은 정보를 위해서, 여기를 봐.

다른 팁

Windows 7의 경우 기본 브라우저 경로 다음 레지스트리 키에서 저장

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

C#을 사용하면 다음과 같이 얻을 수 있습니다.

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

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

귀하의 답변을 바탕으로 원하는 작업을 수행 해야하는이 샘플 코드를 썼습니다 (테스트되지 않음).

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

방금 기능을 만들었습니다.

    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));
    }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top