1、 函数定义
public static bool OpenUrl(string url, bool openInNewWindow)
{
try
{
const string name = @"http\shell\open\command";
RegistryKey openSubKey = Registry.ClassesRoot.OpenSubKey(name, false);
if (openSubKey != null)
{
string fileName = ((string)openSubKey.GetValue(null, null)).Split(new[] { '"' })[1];
if (openInNewWindow)
{
Process process = new Process();
process.StartInfo.FileName = fileName;
process.StartInfo.Arguments = url;
process.Start();
return true;
}
Process.Start(fileName, url);
}
}
catch (Exception)
{
try
{
Process.Start(url);
return true;
}
catch (Exception)
{
return false;
}
}
return true;
}
2、调用
OpenUrl(“http://www.baidu.com”, true);