在Windows 8桌面应用程序的默认浏览器中打开URL

时间:2022-06-27 12:33:41

I am using System.Diagnostics.Process.Start from a desktop application to start the default browser to visit a link, as below. This is using C# with .NET 4.0 on Windows 8 Pro RTM.

我从桌面应用程序使用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
});

This works fine under Windows 7, but under Windows 8 I am getting an exception that can be reproduced in LINQPad. The exceptions are:

这在Windows 7下工作正常,但在Windows 8下我得到一个可以在LINQPad中重现的异常。例外情况是:

UseShellExecute = true gives Win32Exception: Class not registered. UseShellExecute = false gives Win32Exception: The system cannot find the file specified.

UseShellExecute = true给出Win32Exception:Class未注册。 UseShellExecute = false给出Win32Exception:系统找不到指定的文件。

How can open a URL in the default browser?

如何在默认浏览器中打开URL?

2 个解决方案

#1


21  

For WinRT apps only, it's simply

仅适用于WinRT应用程序,它很简单

Launcher.LaunchUriAsync(new Uri("http://www.google.com"));

Take a look here.

看看这里。

#2


5  

It seems that you need to specify the process name under Win8. The answer below comes from Armin's answer here.

您似乎需要在Win8下指定进程名称。以下答案来自Armin的回答。

var startInfo = new ProcessStartInfo("explorer.exe", @"http://www.google.com");
Process.Start(startInfo);

#1


21  

For WinRT apps only, it's simply

仅适用于WinRT应用程序,它很简单

Launcher.LaunchUriAsync(new Uri("http://www.google.com"));

Take a look here.

看看这里。

#2


5  

It seems that you need to specify the process name under Win8. The answer below comes from Armin's answer here.

您似乎需要在Win8下指定进程名称。以下答案来自Armin的回答。

var startInfo = new ProcessStartInfo("explorer.exe", @"http://www.google.com");
Process.Start(startInfo);