Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Process.Start(url) fails

Tags:

I have a WinForms application targeting .NET 2.0. We have a report that one of our buttons doesn't work, all it does is open a webpage in their default browser. Looking through the logs I can see Process.Start() fails because it cannot find the file. The problem is that we pass a string url into the Start() method, so I cannot understand why it generates this message.

Here is the exception from the logs:

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) 

And for completeness:

Process.Start(url); 

Where url has a value of something like: "http://www.example.com"

After searching online I came across this blog with the same issue. The difference is this was specific to Windows 8. He discovered some browsers are not registering themselves correctly when being installed. This has since been fixed as the browsers released updates. (Blog dated shortly after Windows 8 release).

I could understand it if our customer didn't have a browser installed. But this is not the case. I've also loaded a Windows XP VM, and tried removing all associations for files types of .html, URL: HyperText Transfer Protocol, etc, from the Folder Options window under the File Types tab. But I cannot reproduce the problem.

Does anyone have any ideas why this might fail, and / or how I can reproduce the error?

As a side note, our customer is running Windows XP.

like image 692
Darren Hale Avatar asked Feb 17 '14 17:02

Darren Hale


People also ask

What does Process start do?

Start(ProcessStartInfo)Starts the process resource that is specified by the parameter containing process start information (for example, the file name of the process to start) and associates the resource with a new Process component.

What is Process start info c#?

ProcessStartInfo is used together with the Process component. When you start a process using the Process class, you have access to process information in addition to that available when attaching to a running process. You can use the ProcessStartInfo class for better control over the process you start.

How do I start a Process in VB net?

Start another application using your . NET code As a . NET method, Start has a series of overloads, which are different sets of parameters that determine exactly what the method does. The overloads let you specify just about any set of parameters that you might want to pass to another process when it starts.


1 Answers

Had the same problem, solved without IE fallback.
This will make it behave more like just typing it in the 'Run' window:

Process.Start(new ProcessStartInfo("https://www.example.com") { UseShellExecute = true }); 

Note that I'm setting UseShellExecute = true

The default is supposed to be true on .Net Framework, and false on .Net Core
and UWP apps should not use this flag. see docs
(I was running on .Net Core)

like image 101
SimpleVar Avatar answered Sep 20 '22 11:09

SimpleVar