C#使用默认浏览器打开URL
在.NET Framework中可以使用以下代码打开默认URL
C# 全选
System.Diagnostics.Process.Start(url);
这种方案在 .NET Core 中执行会报错
在.NET Core中实现使用默认浏览器打开指定url
C# 全选
string url = "https://www.yesdotnet.com";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false; //不使用shell启动
p.StartInfo.RedirectStandardInput = true;//喊cmd接受标准输入
p.StartInfo.RedirectStandardOutput = false;//不想听cmd讲话所以不要他输出
p.StartInfo.RedirectStandardError = true;//重定向标准错误输出
p.StartInfo.CreateNoWindow = true;//不显示窗口
p.Start();//向cmd窗口发送输入信息 后面的&exit告诉cmd运行好之后就退出
p.StandardInput.WriteLine("start " + url + "&exit");
p.StandardInput.AutoFlush = true;
p.WaitForExit();//等待程序执行完退出进程
p.Close();
版权声明:本文为YES开发框架网发布内容,转载请附上原文出处连接
post 张国生