Process.Start to open an URL, getting an Exception?

前端 未结 4 640
慢半拍i
慢半拍i 2020-12-06 05:56

I\'m trying to open an URL following a simple method written all over google and even MSDN. But for unknown reasons I get an Exception as follows:

Win32Except         


        
相关标签:
4条回答
  • 2020-12-06 06:46

    This is apparently machine-specific behaviour (http://devtoolshed.com/content/launch-url-default-browser-using-c).

    The linked article suggests using Process.Start("http://myurl") but catching Win32Exception and falling back to Process.Start("IExplore.exe", "http://myurl"):

    try
    {
      Process.Start("http://myurl");
    }
    catch (Win32Exception)
    {
      Process.Start("IExplore.exe", "http://myurl");
    }
    

    Sadly after trying almost everything, this was the best I could do on my machine.

    0 讨论(0)
  • 2020-12-06 06:48

    I had a similar issue trying this with .NET Core and getting a Win32Exception, I dealt with it like so:

    var ps = new ProcessStartInfo("http://myurl")
    { 
        UseShellExecute = true, 
        Verb = "open" 
    };
    Process.Start(ps);
    
    0 讨论(0)
  • 2020-12-06 06:48

    Throw start in front of it, if you want to launch in the default browser:

    new ProcessStartInfo("start http://github.com/tbergeron/todoTxt");
    
    0 讨论(0)
  • 2020-12-06 06:52

    You are looking for the string overload of Process.Start():

    Process.Start("http://github.com/tbergeron/todoTxt");
    
    0 讨论(0)
提交回复
热议问题