您可以从RegKey获取默认浏览器应用程序的路径吗?
从C#/ .NET获取它的最佳方法是什么?
答案 0 :(得分:16)
这是你想要的钥匙:
HKEY_LOCAL_MACHINE \ SOFTWARE \类\ HTTP \壳\开放\命令
如果你需要,可以快速registry tutorial for C#。
修改强>:
对于每用户设置,请使用以下密钥:
HKEY_CLASSES_ROOT \ HTTP \壳\开放\命令
(HKCR有机器和用户设置,用户优先)。
请注意,这可能不适用于Vista 。有关详细信息,请see here。
答案 1 :(得分:1)
for 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();
答案 2 :(得分:1)
根据你的答案,我写了这个示例代码,应该做你想要的(未经测试)
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;
}
答案 3 :(得分:1)
我刚刚为此做了一个功能:
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));
}