tags:

views:

259

answers:

7

Process.Start("IExplore.exe");

Does this always work, on every machine ? If not, how to do it properly ?

... EDIT: .................................

The problem with Process.Start("http://www.example.com/"); is that we have to target a local html file, with some querystring specifying which page to load in the html frameset. So our URL looks like the following:

G:\PathToHelpFolder\index.html#search?page=1.html

If you pass this path to Process.Start, an error is generated: "cannot find the file". This is caused by the querystring at the end. (#search?page=1.html)

So, we have to start explorer (or default browser would be better) with the filepath as a command line argument. We found the method above at the MSDN documentation. (Process.Start("IExplore.exe");) Our only question is if this method is reliable enough to deploy to a commercial app. Mono isn't a problem, only windows systems are targeted.

... EDIT : Our solution ......

Our solution was to get the default browser from the registry, and start that with the filename as argument. (as stated in: http://stackoverflow.com/questions/2646825/launching-default-browser-with-html-from-file-then-jump-to-specific-anchor/2646944#2646944)

+22  A: 

If your goal is to open a browser to go to a specific page, it's better to use just the page URL:

Process.Start("http://www.example.com/");

That way, the user's default browser will be used. (I, for one, would be annoyed to be forced into using IE.)

Thomas
that won't work if you target a local file, and add a querystring ... also +1 for the default browser point ... thanks
Run CMD
This may fail if somebody tries to install Google Chrome on a locked-down (corporate) PC, after which MSIE still works and is default browser, but where the registry is damaged. The solution is to fix the registry contents.
Lars D
+2  A: 

You can just throw a url in there as well. (Process.Start("http://somewebsite.com");) that will always work and use the standard browser.

Jouke van der Maas
+2  A: 

You probably should be directly running a HTML file so that the user's association is honoured. There's nothing more annoying to me, as a user, than having some package force me to use IE when I've clearly set my preferences to use another browser.

paxdiablo
+3  A: 

This should work on every machine that has an executable called IExplore.exe in a location that Process.Start can find by using the PATH environment variable.

Process.Start documentation

Starting a process by specifying its file name is similar to typing the information in the Run dialog box of the Windows Start menu. Therefore, the file name does not need to represent an executable file. It can be of any file type for which the extension has been associated with an application installed on the system. For example the file name can have a .txt extension if you have associated text files with an editor, such as Notepad, or it can have a .doc if you have associated.doc files with a word processing tool, such as Microsoft Word. Similarly, in the same way that the Run dialog box can accept an executable file name with or without the .exe extension, the .exe extension is optional in the fileName parameter. For example, you can set the fileName parameter to either "Notepad.exe" or "Notepad".

If someone has renamed or removed IExplore.exe, or it's in a location that's not in the PATH environment variable then it won't work.

However, if your goal is to open a browser then I'd go with passing the URL as others have suggested.

ChrisF
+5  A: 

I once needed the default browser's name (without opening) for a stupid application I built, I found a great tutorial over here: http://ryanfarley.com/blog/archive/2004/05/16/649.aspx

Blank6
A: 

You could create a simple HTML file that redirects the the actual link you want, then start the process pointing to that simpler url.

ck
A: 

Try this:

Process.Start("file:///g:/PathToHelpFolder/index.html#search?page=1.html");

Carl
doesn't work ... querystring gets cut off, even when enclosing the whole string in quotation marks ...
Run CMD