Opening a browser window from a Window Form

J

James CC

Hi there,

I'm trying to open a web page in a browser. I wanted to open the default
browser on the computer, rather than limiting it to IE, so I did the
following (web page has been changed to protect the innocent! ;oD)

// botch - this gives an error if blocked by zonealarm or other firewall
try
{
System.Diagnostics.Process.Start("http://www.google.com/");
}
catch (Exception ex)
{
MessageBox.Show("Error while opening browser window. Check your firewall
permissions.\nError returned was : " + ex.Message);
}

As the comment shows, if the .NET application's access to the internet is
blocked by ZoneAlarm (or a similar 'outward bound blocking' firewall) then
the Start() fails - but it does not return an error or exception, or indeed
return at all. Stepping through in the debugger shows that the Start() never
returns and the next line is not executed.

Strangely, the UI keeps working, kind of; if you then do the above a second
time then it gives an exception of 'The system cannot find the file
specified'.

Of course it works fine if the firewall allows access, but that's not much
comfort.

Does anyone have a solution? Failing that, can someone suggest another way
to open a web page in the default browser that does not have the above
problem. Failing that, can someone suggest the best way to open a web page
in IE without the above problem?

Thanks tons - this one's driving me crazy...

James CC
 
K

Kevin Spencer

Firewalls are always a consideration when doing a network operation, as long
as firewalls are installed on the system. Whether a network call is granted
is determined by the Firewall configuration. Are you able to open the
default browser on the computer and open that web page? If so, it is the
account under which your app is attempting to open the browser that is
restricted.

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

Any experience you can walk away from
is a good one.
 
J

James CC

Dear Kevin,

Kevin Spencer said:
Are you able to open the default browser on the computer and open that web
page?

Using what C# command? If
System.Diagnostics.Process.Start("http://www.google.com/") then, depending
on the firewall setup, no. It fails, but without raising an exception or
returning from the Start() method, as outlined in my initial post.

Is there another way of finding or running the default browser?

I can run IE (whether it is the default or not), by doing Start() with
"C:\\Program Files\\Internet Explorer\\iexplore.exe" as the command and
"http://www.google.com/" as the parameter. That bypasses the firewall rules
by using an existing application with existing permissions from the
firewall. If I could find out the path of the default browser then I could
probably do the same for that.
If so, it is the account under which your app is attempting to open the
browser that is restricted.

Yes; I would point out (for information's sake only) that ZoneAlarm blocks
access according to the application rather than the user or account AFAIK.
In other words, it catches my application trying to access the internet when
the System.Diagnostics.Process.Start("http://www.google.com/") method is
processed and asks the user if my application should be allowed to access
the internet (or follows the rule set up, if there is one).

Thanks for your reply and your help - I was feeling like the proverbial tree
in the forest there for a moment! ;o)

James
 
J

James CC

Update :

With Kevin's input and a bit of poking around I have half the puzzle.

Does anyone know how to find out what the default browser is, and what its
executable path is?

I've found the following registry keys that might be appropriate...

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\htmlfile\shell\open\command
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\HTTP\shell\open\command
Maybe the default command for the appropriate file type?

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm\OpenWithList
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\OpenWithList
A list of the applications used for opening a particular file type?

HKEY_CLASSES_ROOT\Applications\iexplore.exe\shell\open\command
Path for application - but the list is not complete - I don't see Firefox
there, for example

Anyone know which of those is best?

James
 
J

James CC

Update :

With Kevin's input and a bit of poking around I have half the puzzle.

Does anyone know how to find out what the default browser is, and what its
executable path is?

I've found the following registry keys that might be appropriate...

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\htmlfile\shell\open\command
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\HTTP\shell\open\command
Maybe the default command for the appropriate file type?

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm\OpenWithList
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\OpenWithList
A list of the applications used for opening a particular file type?

HKEY_CLASSES_ROOT\Applications\iexplore.exe\shell\open\command
Path for application - but the list is not complete - I don't see Firefox
there, for example

Anyone know which of those is best? Or is there another, better way?

James
 
J

James CC

Update :

With Kevin's input and a bit of poking around I have half the puzzle.

Does anyone know how to find out what the default browser is, and what its
executable path is?

I've found the following registry keys that might be appropriate...

HKEY_LOCAL_MACHINE\SOFTWARE\Classes\htmlfile\shell\open\command
HKEY_LOCAL_MACHINE\SOFTWARE\Classes\HTTP\shell\open\command
Maybe the default command for the appropriate file type?

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.htm\OpenWithList
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\OpenWithList
A list of the applications used for opening a particular file type?

HKEY_CLASSES_ROOT\Applications\iexplore.exe\shell\open\command
Path for application - but the list is not complete - I don't see Firefox
there, for example

Anyone know which of those is best? Or is there another, better way?

James
 
K

Kevin Spencer

Hi James,

I think you may be on the right track. From the registry keys you posted, as
each set of file extensions is set up per user, I guessed that the
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
registry key is where you need to look. However, that's as far as my
knowledge goes. I did find an article that may help:

http://msdn.microsoft.com/msdnmag/issues/1100/Registry/

--
HTH,

Kevin Spencer
Microsoft MVP
Ministry of Software Development
http://unclechutney.blogspot.com

Any experience you can walk away from
is a good one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top