我正在使用以下代码获取默认浏览器的路径和可执行文件:
public static string DefaultWebBrowser
{
get
{
string path = @"\http\shell\open\command";
using (RegistryKey reg = Registry.ClassesRoot.OpenSubKey(path))
{
if (reg != null)
{
string webBrowserPath = reg.GetValue(String.Empty) as string;
if (!String.IsNullOrEmpty(webBrowserPath))
{
if (webBrowserPath.First() == '"')
{
return webBrowserPath.Split('"')[1];
}
return webBrowserPath.Split(' ')[0];
}
}
return null;
}
}
}
并且:
protected static bool Run(string FileName, string Args)
{
try
{
Process proc = new Process();
processInfo.FileName = FileName;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
if(Args != null) proc.StartInfo.Arguments = Args;
proc.Start();
return true;
}
catch (Exception) { }
return false;
}
然后我调用Web浏览器:Run(DefaultWebBrowser, "foo.html")
问题在于:上面的函数正在调用Firefox和IE (我电脑上安装的两个Web浏览器),而不是默认的Internet Explorer。我不知道如何解决这个问题。
编辑
我已经下载并安装了Google Chrome,并将其设置为默认Web浏览器,但奇怪的是,它不会发生上述错误。
ShellExecute
启动默认的Web浏览器以及一些注册表键的路径(你可能已经知道)。最终,用户很可能会通过更改一些默认程序来干预...但你不应该过于担心这个问题,因为在某种程度上是不可避免的。 - Spooky