废话少说,直接上代码。
public static bool OpenBrowser(String url)
{
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
String s = key.GetValue("").ToString();
String browserpath = null;
if (s.StartsWith("\""))
{
browserpath = s.Substring(1, s.IndexOf('\"', 1) - 1);
}
else
{
browserpath = s.Substring(0, s.IndexOf(" "));
}
return System.Diagnostics.Process.Start(browserpath, url)!=null;
}

本文提供了一段使用C#代码实现通过注册表读取默认浏览器路径并启动指定URL的示例。该方法适用于Windows平台,通过解析注册表项来确定默认浏览器的位置。

被折叠的 条评论
为什么被折叠?



