我有一个针对.NET 2.0的WinForms应用程序.我们有一个报告,我们的某个按钮不起作用,它只是在默认浏览器中打开一个网页.查看日志我可以看到Process.Start()失败,因为它无法找到该文件.问题是我们将一个字符串url传递给Start()方法,所以我无法理解为什么它会生成这个消息.
以下是日志的例外情况:
System.ComponentModel.Win32Exception: The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
at *namespace*.Website.LaunchWebsiteAsync(String url)
The system cannot find the file specified
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(String fileName)
at *namespace*.Website.LaunchWebsiteAsync(String url)
Run Code Online (Sandbox Code Playgroud)
为了完整性:
Process.Start(url);
Run Code Online (Sandbox Code Playgroud)
其中url的值类似于:" http://www.example.com "
在网上搜索后,我碰上了这个博客有同样的问题.区别在于这是Windows 8特有的.他发现有些浏览器在安装时没有正确注册.这已经在浏览器发布更新时得到修复.(Windows 8发布后不久发布的博客).
如果我们的客户没有安装浏览器,我可以理解.但这种情况并非如此.我也装一个Windows XP中的VM,并尝试删除所有关联的文件类型.html,URL: HyperText Transfer Protocol文件类型选项卡下等,从文件夹选项窗口.但我无法重现这个问题.
有没有人知道为什么会失败,和/或我如何重现错误?
另外,我们的客户正在运行Windows XP.
Sim*_*Var 35
有同样的问题,在没有 IE 回退的情况下解决了。
这将使它的行为更像是在“运行”窗口中输入它:
Process.Start(new ProcessStartInfo("https://www.example.com") { UseShellExecute = true });
Run Code Online (Sandbox Code Playgroud)
请注意,我正在设置 UseShellExecute = true
默认应该true在.Net Framework 上,并且false在.Net Core
和 UWP 上的应用程序不应使用此标志。查看文档
(我在 .Net Core 上运行)
Dus*_*gen 12
尝试使用explorer.exe了fileName明确.
正如在Windows 8/Chrome上打破的Process.Start(url)中所详述的那样,还有其他选择吗?
Process.Start("explorer.exe", url);
Run Code Online (Sandbox Code Playgroud)