CSharp調用默認浏覽器打開網頁的幾種方法

private void button1_Click(object sender, EventArgs e)
{
//從注冊表中讀取默認浏覽器可執行文件路徑
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@httpshellopencommand);
string s = key.GetValue().ToString();
//s就是你的默認浏覽器,不過後面帶了參數,把它截去,不過需要注意的是:不同的浏覽器後面的參數不一樣!
//D:Program Files (x86)GoogleChromeApplicationchrome.exe -- %1
System.Diagnostics.Process.Start(s.Substring(0, s.Length - 8), http://blog.csdn.net/testcs_dn);
}
private void button2_Click(object sender, EventArgs e)
{
//調用系統默認的浏覽器
System.Diagnostics.Process.Start(explorer.exe, http://blog.csdn.net/testcs_dn);
}
private void button3_Click(object sender, EventArgs e)
{
//調用系統默認的浏覽器
System.Diagnostics.Process.Start(http://blog.csdn.net/testcs_dn);
}
private void button4_Click(object sender, EventArgs e)
{
//調用IE浏覽器
System.Diagnostics.Process.Start(iexplore.exe, http://blog.csdn.net/testcs_dn);
}
從原理上來講,方法二和方法三應該是一樣的,不過方法三的代碼更短一點。