以前在使用WinForm+.NET 4.6.x的时候,有需要让程序打开指定网页的需求。
    当时的使用方法就是:

    1. System.Diagnostics.Process.Start("https://www.baidu.com");

    但是今天在使用WPF+.NET5时,发现上述代码无法正常工作,会提示错误:
    System.ComponentModel.Win32Exception:“系统找不到指定的文件。”
    image.png
    百度搜了一下没找到相关结果,但是在Stack Overflow上很轻松地就找到了解决方式,用以下代码替代即可:

    1. string url = "https://www.baidu.com";
    2. var psi = new ProcessStartInfo
    3. {
    4. FileName = url,
    5. UseShellExecute = true
    6. };
    7. Process.Start(psi);

    原帖地址: