Hi Nicholas,
I don't know how to find the call stack ot type of exeption, or I'm just not
familiar with the terms you are using (my ignorance), but I will try to
answer:
Executing the code:
-------------------------------
string target=
http://www.microsoft.com;
System.Diagnost ics.Process.Sta rt(target);
causes an error with the following message:
-------------------------------------------
An unhandled exception of type 'System.Compone ntModel.Win32Ex ception'
occurred in system.dll
Additional information: The system cannot find the file specified
The output panel displays the information below:
-----------------------------------------------------------
An unhandled exception of type 'System.Compone ntModel.Win32Ex ception'
occurred in system.dll
Additional information: The system cannot find the file specified
Unhandled Exception: System.Componen tModel.Win32Exc eption: The system cannot
find the file specified
at System.Diagnost ics.Process.Sta rtWithShellExec uteEx(ProcessSt artInfo
startInfo)
at System.Diagnost ics.Process.Sta rt()
at System.Diagnost ics.Process.Sta rt(ProcessStart Info startInfo)
at System.Diagnost ics.Process.Sta rt(String fileName)
at WindowsApplicat ion3.Main_form. toolBar1_Button Click(Object sender,
ToolBarButtonCl ickEventArgs e) in e:\ms projects\email reference\visua l
studio projects\email reference - main\form_main. cs:line 3533
at System.Windows. Forms.ToolBar.O nButtonClick(To olBarButtonClic kEventArgs e)
at System.Windows. Forms.ToolBar.W mReflectCommand (Message& m)
at System.Windows. Forms.ToolBar.W ndProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Send Message(IntPtr hWnd, Int32
msg, IntPtr wParam, IntPtr lParam)
at System.Windows. Forms.Control.S endMessage(Int3 2 msg, IntPtr wparam, IntPtr
lparam)
at System.Windows. Forms.Control.R eflectMessageIn ternal(IntPtr hWnd, Message&
m)
at System.Windows. Forms.Control.W mCommand(Messag e& m)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
at System.Windows. Forms.Container Control.WndProc (Message& m)
at System.Windows. Forms.Form.WndP roc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Call WindowProc(IntP tr wndProc,
IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows. Forms.NativeWin dow.DefWndProc( Message& m)
at System.Windows. Forms.Control.D efWndProc(Messa ge& m)
at System.Windows. Forms.Control.W mMouseUp(Messag e& m, MouseButtons button,
Int32 clicks)
at System.Windows. Forms.Control.W ndProc(Message& m)
at System.Windows. Forms.ToolBar.W ndProc(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.OnMe ssage(Message& m)
at System.Windows. Forms.ControlNa tiveWindow.WndP roc(Message& m)
at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
at System.Windows. Forms.UnsafeNat iveMethods.Disp atchMessageW(MS G& msg)
at
System.Windows. Forms.Component Manager.System. Windows.Forms.U nsafeNativeMeth o
ds+IMsoComponen tManager.FPushM essageLoop(Int3 2 dwComponentID, Int32 reason,
Int32 pvLoopData)
at System.Windows. Forms.ThreadCon text.RunMessage Loop(Int32 reason,
ApplicationCont ext context)
at System.Windows. Forms.Applicati on.Run(Form mainForm)
at WindowsApplicat ion3.Main_form. Main() in e:\ms projects\email
reference\visua l studio projects\email reference - main\form_main. cs:line
2894
The program '[3384] Email reference.exe' has exited with code 0 (0x0).
"Nicholas Paldino [.NET/C# MVP]" <ni************ **@exisconsulti ng.com> wrote
in message news:O3******** *****@TK2MSFTNG P12.phx.gbl...
Michel,
What is the call stack and the type of the exception when you try it
the first way? Perhaps there is a problem with a lower-level component
somewhere.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- ni************* *@exisconsultin g.com
"Michel H" <ze*********@ho tmail.com> wrote in message
news:bk******** **@news.brutele .be... Hello everyone,
While it seems simple to me, I just want to have a URL in my windows
application that people can click and then launch the URL in the default
browser. Same thing with a mailto: link.
Here is the code i'm trying to use which comes straight from the
microsoft site:
string target= "http://www.microsoft.c om";
try
{
System.Diagnost ics.Process.Sta rt(target);
}
catch
(
System.Componen tModel.Win32Exc eption noBrowser)
{
if (noBrowser.Erro rCode==-2147467259)
MessageBox.Show (noBrowser.Mess age);
}
catch (System.Excepti on other)
{
MessageBox.Show (other.Message) ;
}
However, I get a "The system cannot find the file specified" .......
Ok so I tried something else, such as calling the Shell32.dll library:
I made a class as such:
public class Class_shell32
{
[DllImport("Shel l32.dll",CharSe t=CharSet.Auto)]
public static extern IntPtr ShellExecute(
IntPtr hwnd,
string lpVerb,
string lpFile,
string lpParameters,
string lpDirectory,
int nShowCmd );
}
and I call it like this:
IntPtr returned_handle ;
returned_handle = Class_shell32.S hellExecute(thi s.Handle,
"http://www.cnn.com","" ,null,null,3);
While this doesn't cause an error, the value of returned_handle is less
than 32, indicating that the document could not be launched....
Anyone have any ideas?
Michel.