Click to See Complete Forum and Search --> : Launching browser problem
markiemooster
November 23rd, 2004, 01:28 PM
Can someone please tell me why the following code throws an exception:
// Launch browser/other app to display help page
System.Diagnostics.Process p= new System.Diagnostics.Process();
p.StartInfo.FileName= @"http://10.4.1.44";
p.StartInfo.UseShellExecute= true;
p.StartInfo.Verb= "open";
p.Start();
Windows Start button -> Run and http://10.4.1/44 opens a browser. And so does my use of ShellExecute and the same URL in a C++ test program.
What is different about my C# code? I'm at my wit's end.
Thanks,
Mark
PS I'm using Visual Studio.NET 2002 (so it compiles code using the version 1.0 of the .NET framework)
Norfy
November 24th, 2004, 04:38 AM
What's the exception?
I tried your code and it worked fine! When you say the C++ version worked, is that C++ .NET?
The only problem I've had in this area when the app doesn't open, is that the file does not have an associated app in the Folder Options. is the "URL:HyperText Transfer Protocol" entry pointing at a browser?
System.Diagnostics.Process p= new System.Diagnostics.Process();
p.StartInfo.FileName= @"http://www.codeguru.com/forum/showthread.php?t=319246";
p.StartInfo.UseShellExecute= true;
p.StartInfo.Verb= "open";
try
{
p.Start();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
markiemooster
November 24th, 2004, 05:31 AM
I tried your code (and mine) and I received the following exception:
System.ComponentModel.Win32Exception: The requested lookup key was not found in any activation context
at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start
at <my method:line no>
Frankly I'm bewildered. It's all so simple what could be going wrong?
My C++ test program was not .NET but compiled code for Win32.
My app monitors a folder and if a new file appears in the folder it launches a form with a Help button. When the user presses the Help button the browser is supposed to open.
Does anyone have any other ideas?
Thanks,
Mark
PS I'm running XP with SP2.
Norfy
November 24th, 2004, 07:04 AM
Out of interest does this work?
System.Diagnostics.Process p= new System.Diagnostics.Process();
p,StartInfo.Filename = "explorer.exe";
p.StartInfo.Arguments = @"http://www.codeguru.com";
p.Start();
Are you using XP themes? ie. Application.EnableVisualStyles();
markiemooster
November 24th, 2004, 07:38 AM
Yes it does! Thankyou so much. You are a legend.
I still don't understand why there is an issue but at least that solves the problem in the short term. It would be nice to know why the issue occurs. Maybe I'll never know!
Thanks again,
Mark
PS Application.EnableVisualStyles() is only available in .NET version 1.1 so I'm not able to use it.
Norfy
November 24th, 2004, 07:50 AM
Great!
The reason I mentioned the XPThemes bit is there is a known bug with activation contexts and explorer. Apparently if you do an Application.DoEvents() immediately after the Application.EnableVisualStyles(); it fixes the problem. Of course if you're not using this then it's totally irrelevant.
Now if you cut and paste "Thankyou so much. You are a legend" into the "Rate This Post", that'll make both of us happy! :wave:
Andy Tacker
November 24th, 2004, 07:57 AM
wow!!!
how about
System.Diagnostics.Process.Start("http://www.codeguru.com");
It simply works :)
Andy Tacker
November 24th, 2004, 07:58 AM
Great!
Now if you cut and paste "Thankyou so much. You are a legend" into the "Rate This Post", that'll make both of us happy! :wave:hehehe Norfy...
waterscapes
May 3rd, 2007, 10:26 AM
Let Microsoft do the work for you in solving this problem.
Do the following;
1. open your browser
2. go to options in the topmenu
3. go to internet options
4 where it is written homepage - use current - type in [url]http://update.microsoft.com/microsoftupdate/
5. OK or Apply and close.
Close your browser.
Open your browser and the Microsoft update page will be opened automatically.
Click Express and smile while the updater does all the work for you.
Have a drink, call a friend, enjoy yourself as I did.
Greetings
Henry
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.