在Windows 8桌面应用程序的默认浏览器中打开URL
我从桌面应用程序使用System.Diagnostics.Process.Start
启动默认浏览器以访问链接,如下所示。 这是在Windows 8 Pro RTM上使用C#和.NET 4.0。
System.Diagnostics.Process.Start(new ProcessStartInfo { FileName = @"http://www.google.com", UseShellExecute = true });
这在Windows 7下工作正常,但在Windows 8下我得到一个可以在LINQPad中重现的exception。 例外情况是:
UseShellExecute = true
给出Win32Exception:Class未注册。 UseShellExecute = false
给出Win32Exception:系统找不到指定的文件。
如何在默认浏览器中打开URL?
仅适用于WinRT应用程序 ,它很简单
Launcher.LaunchUriAsync(new Uri("http://www.google.com"));
看看这里 。
您似乎需要在Win8下指定进程名称。 以下答案来自Armin的回答。
var startInfo = new ProcessStartInfo("explorer.exe", @"http://www.google.com"); Process.Start(startInfo);