当用户在我的应用中进行特定选择时,我尝试启动浏览器窗口。我通过搜索此站点找到了执行此操作的代码。有趣的是,即使我将 Firefox 设置为我的默认浏览器,它也总是返回 IE,因此我的代码会打开一个 IE 窗口。我宁愿不要发生这种情况。我已经检查了注册表中 HTTP 和 HTTPS 的密钥,并将它们设置为 Firefox。 Firefox 说它是默认浏览器。现在我注意到,如果我从开始菜单中搜索某些内容并且它想访问互联网以获取结果,它还会打开一个 IE 窗口,而不是将我带到 Firefox 中的一个新选项卡。正在寻找更多的地方。
返回默认浏览器的代码:
//set the registry key we want to open
regKey = Registry.ClassesRoot.OpenSubKey("HTTP\\shell\\open\\command", false);
//get rid of the enclosing quotes
name = regKey.GetValue(null).ToString().ToLower().Replace("" + (char)34, "");
// Remove any command line arguments...
if (!name.EndsWith("exe"))
// Remove anything after the .exe...
name = name.Substring(0, name.LastIndexOf(".exe") + 4);
然后启动应用程序:
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = name;
startInfo.Arguments = @"myURL";
Process.Start(startInfo);