You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

C# WPF点击按钮跳转网页触发Win32Exception系统找不到指定文件

异常根因
  • 此问题仅出现在.NET Core 3.0+、.NET 5及更高版本的项目中:System.Diagnostics.Process.Start 方法的默认行为被调整,不再支持直接传入URL字符串调用默认浏览器打开链接
  • 系统会将传入的URL识别为本地文件路径进行查找,找不到对应文件就抛出 System.ComponentModel.Win32Exception,提示“系统找不到指定文件”
修复代码

将点击事件代码修改为以下形式,显式开启UseShellExecute参数,调用系统Shell执行打开逻辑,兼容所有.NET版本:

private void GetKey_Click(object sender, RoutedEventArgs e)
{        
    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo("https://pastebin.com/raw/example") 
    { 
        UseShellExecute = true 
    });
}

针对.NET 6及更高版本,也可以使用更简洁的写法:

private void GetKey_Click(object sender, RoutedEventArgs e)
{        
    System.Diagnostics.Process.Start("explorer.exe", "https://pastebin.com/raw/example");
}

内容的提问来源于stack exchange,提问作者THEPROGAMER ROBLOX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 03:39:02