Opening a URL in the default browser in a Windows 8 desktop application

我们两清 提交于 2019-12-18 14:53:52

问题


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(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:

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

How can open a URL in the default browser?


回答1:


For WinRT apps only, it's simply

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

Take a look here.




回答2:


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

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


来源:https://stackoverflow.com/questions/12501174/opening-a-url-in-the-default-browser-in-a-windows-8-desktop-application

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!