473,796 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

c# and launch of default browser, mail

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.


Nov 15 '05 #1
3 2908
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.

Nov 15 '05 #2
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.

Nov 15 '05 #3


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.


Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
460
by: Thejus | last post by:
Hi, I want to launch Outlook express with attachment. Any ideas ? Thanks Thejus
5
2761
by: Thejus | last post by:
Hi, I want to launch Outlook express with attachment. Any ideas ? Thanks Thejus
3
2028
by: Scott | last post by:
I wish to have a link on a page that launches a new browser before it loads the target link. The standard _new and _blank include the parent browser's cookies. Is there an alternative method that excludes these cookies? Thanks in advance
1
1375
by: Larry Rebich | last post by:
How do I launch the default e-mail agent using Asp.Net 2.0 and VB 2005? I have a button on the page called 'Send e-Mail'. I want to launch the user's default e-mail agent. The message will contain a send to address, subject and text. No attachments will be sent. Thanks,
0
9684
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10236
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10182
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10017
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6793
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5577
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3734
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.