主要是这个代码:
//调用系统默认的浏览器
System.Diagnostics.Process.Start("https://blog.youkuaiyun.com/testcs_dn/article/details/42246969");
但是有几个不同的使用:
上面的代码还可以写为:
System.Diagnostics.Process.Start("explorer.exe", "https://blog.youkuaiyun.com/testcs_dn/article/details/42246969");
调用IE浏览器:
System.Diagnostics.Process.Start("iexplore.exe", "https://blog.youkuaiyun.com/testcs_dn/article/details/42246969");
如果从注册表中读取默认浏览器,则为:
这个要注意截取的部分,不同的浏览器后面的参数不一样,截取的长度就不一定,容易报错,不建议使用
RegistryKey key = Registry.ClassesRoot.OpenSubKey(@"http\shell\open\command\");
string exe = key.GetValue("").ToString();
//exe 就是你的默认浏览器,后面的参数需要去掉,例如'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe' -- '%1'
System.Diagnostics.Process.Start(exe .Substring(0, s.Length - 8),"https://blog.csdn.net/testcs_dn/article/details/42246969");