4

If I try to use:

System.Diagnostics.Process.Start("http://google.com");

the following error occurs:

System.ComponentModel.Win32Exception: "The system cannot find the file specified"

I use win10 and visual studio.

Actually I can't find a solution or something like that. Maybe it's because i'm behind a proxy ? Or could there be any other problem ? And if yes, could you help me to fix it ?

SpiderCode
  • 10,062
  • 2
  • 22
  • 42
Morta
  • 224
  • 1
  • 14
  • @derloopkat,no,`System.Diagnostics.Process.Start` can open links in your default web application too – Software Dev Mar 28 '18 at 08:29
  • If you're using .Net Core, [this answer](https://stackoverflow.com/a/43232486/5443550) might be of use – Diado Mar 28 '18 at 08:31
  • Cannot reproduce. That code works as expected – Steve Mar 28 '18 at 08:31
  • @Steve that's the problem.. I think if this error was normal, I could find a solution in another Thread :P – Morta Mar 28 '18 at 08:34
  • If you can't make it work then you have some kind of problem in your machine where there is no association between these links and your default browser. Glad you have found a workaround – Steve Mar 28 '18 at 08:47

2 Answers2

12

Can you try below work around:

System.Diagnostics.Process.Start("cmd","/c start http://www.google.com");
SpiderCode
  • 10,062
  • 2
  • 22
  • 42
  • 1
    @Morta: I just applied another approach. you can find more details on https://ss64.com/nt/start.html – SpiderCode Mar 28 '18 at 08:37
  • @Morta,take a look at my solution :) and SpiderCoder, upvote deserved – Software Dev Mar 28 '18 at 08:39
  • 2
    Thanks this solution helped me, i found you can also use ```System.Diagnostics.Process.Start(new ProcessStartInfo("http://google.com"){ UseShellExecute=true});``` – RamWill Dec 20 '20 at 14:08
1

I think I should document this here since I haven't seen many answers explaining why that error happens

The actual problem you are facing is that you are using the incorrect overload. The only parameter accepted by this overload is a file or document name. According to MSDN, URLs are NOT consider documents.

You find that statement hidden in one of the examples in the documentation here...

https://msdn.microsoft.com/en-us/library/53ezey2s(v=vs.110).aspx

enter image description here

Now, the correct overload is...

System.Diagnostics.Process.Start(string fileName, string arguments);

where filename is name of the process you want to start (IE, Chrome, etc.) and arguments in this case would be the URL to pass to the process. More infor here...

https://msdn.microsoft.com/en-us/library/h6ak8zt5(v=vs.110).aspx

Leo
  • 14,625
  • 2
  • 37
  • 55
  • Thank you. But actually, if I use Process.Start("IExplore.exe", "www.google.com");, the same error occurs.. – Morta Mar 28 '18 at 08:52