1
System.Diagnostics.Process.Start("www.google.com"); 

It works perfect, but how about just 'google.com'?

I tried to do it like this

System.Diagnostics.Process.Start("google.com"); 

but it doesn't work with the same links and throws an exception. Any suggestions?

2
  • 2
    where is the problem just to use "www.google.com"? Commented Oct 28, 2014 at 10:16
  • 2
    Did you try "http://google.com" ? Commented Oct 28, 2014 at 10:17

1 Answer 1

6

Add the protocol (http:// or https:// for example), then the handler knows what to do:

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

Windows checks the file extension list, and that included protocols too. There it finds http maps to your browser. You can consider to be 'lucky' it detects www. too, but I wouldn't depend on it too much.

Sign up to request clarification or add additional context in comments.

9 Comments

No luck needed. The www prefix is detected by default.
What I meant was that "www.<any url>" works always with default settings.
@JensG: In this case yes, but it is safer to depend on the protocol then on the format of the url.
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\URL\Prefixes
@user3861153: You should not rely on this behaviour, just add http://. I fully agree with that aspect of the question. Never said anything different.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.