views:

1370

answers:

3

Okay I'm having a brain fart here. This should be simple, but I'm missing something.

I've got a win form and I'm trying to launch a web page when I click a button. The code for the button is here:

private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            System.Diagnostics.Process.Start("http://www.google.com");
        }
        catch (Win32Exception ex)
        {
            Console.WriteLine(ex.Message);
            lblError.Text = ex.Message;
        }            
    }

When I run this on my computer, it works fine. On other computers, it only works if you have a browser already open. If you don't have a browser open, it opens the browser then just hangs. What gives?

I've also tried

`System.Diagnostics.Process.Start("IExplore.exe", "http://www.google.com");`

ignoring the default browser (something I'd like to avoid but if it works, it works). I get the same result.

Thanks for your help.

EDIT: I'm also open to other methods of launching a web page with a button if any of you can think of one.

A: 

There's probably a better way to do it but this works...

System.Diagnostics.Process.Start("cmd","/c start http://www.google.com");
CptSkippy
Thanks! I'll give that a try tomorrow morning.
MayorAwesome
I just tried System.Diagnostics.Process.Start("http://www.google.com"); and it worked fine...
CptSkippy
Yeah that's the weird thing. It works FINE on two computers, but barfs on two other computers. I'm trying to figure out what the difference between them is. I'm gonna try the System.Diagnostics.Process.Start("cmd","/c start http://www.google.com") and see if that magically works.
MayorAwesome
System.Diagnostics.Process.Start("cmd","/c start http://www.google.com"); works fine on two computers, but not the test computers. I think the difference is that the two computers it's working on have .Net installed. I can't guarantee that the target computers are going to have it installed. To get around that, I'm using Thinstall, a VMWare app that packages the program so I can deploy it (theroetically) anywhere. https://thinstall.com/
MayorAwesome
A: 

Okay, I got it working. I took Thinstall out of the equation and it magically works on every computer. Thanks guys for the help and suggestions.

MayorAwesome
A: 

How do I open my URL link in a new window or new tab (depending on the browswer) but without knowing which browser?

Anand