shellexecute in C#

  • Thread starter Thread starter Le, Thanh-Nhan
  • Start date Start date
Le, Thanh-Nhan,

Take a look at the Process class in the help. I have posted a sample for
you below.

Hope this helps.
 
Hi,
I have tried with System.Diagnostics.Process, but in my case it doesn't work.

I want to call
ShellExecute(0, "open", "mailto:[email protected]?body=yyy&subject=wwwwww, 0, 0, 5)
to open the standart email program ..., as when we click on the hyperlinks mailto:[email protected]?body=yyy&subject=wwwwww

Thanks
Nhan
 
Le said:
Hi,
Is there a same function in .Net as API shellexecute?

Thanks
Nhan

Yeah, System.Diagnostics.Process class. You can start a program there.

Laimis
 
Le, Thanh-Nhan,

You can still use the Process class. Try the sample that I have posted
below (watch for line wrap).

I hope this helps.
--------------------

System.Diagnostics.Process p = new System.Diagnostics.Process();
string myMail =
String.Format("mailto:{0}?subject={1}&body={2}","(e-mail address removed)", "Subject
Goes Here", "This is the body of the email");
p.StartInfo.FileName = myMail;
p.Start();
 
Thanks for your help.
I have tried your code, but it doesn't work regrettably.

Nhan
 
but I want to call a standard email programm on the system of users
computer. I don't know which program will be.
In VB 6 I use
sEmail = "mailto:[email protected]?body=yyy&subject=wwwwww"
call ShellExecute(0, "open", sEmail, 0, 0, 5)

ShellExecute will start email program (as Outlook) and open a window for the
email the given informs.

Thanks
Nhan
 
The example provided was pretty close. All that you need to do in
addition is to tell the process to use ShellExecute. Let me know if
this still doesn't work for you.

string commandText = "mailto:[email protected]";
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo.FileName = commandText;
proc.StartInfo.UseShellExecute = true;
proc.Start();
 
Thanks,
I have tried with UseShellExecute.
It still doesn't work. I think, my email system had a problem, or my .NET is
not installed correctly (???) . When I the code to open a text file, it
works, the file is opened in notepad.

Nhan
 
You can also call ShellExecute directly through Interop if you wish.

<code>
//ShellExecute declaration
[System.Runtime.InteropServices.DllImport("shell32.dll")]
private static extern long ShellExecute(Int32 hWnd, string lpOperation,
string lpFile, string lpParameters, string lpDirectory, long nShowCmd);
</code>
 
This should work:
Process myProcess = new Process();
ProcessStartInfo myProcessStartInfo = new
ProcessStartInfo("rundll32.exe" );
myProcessStartInfo.UseShellExecute = false;
myProcessStartInfo.Arguments= "url.dll ,FileProtocolHandler
mailto:www.microsoft.com";
myProcess.StartInfo = myProcessStartInfo;
myProcess.Start();
myProcess.WaitForExit();
myProcess.Close();

Regards,
Jeff
I want to call
ShellExecute(0, "open", "mailto:[email protected]?body=yyy&subject=wwwwww, 0,
0, 5)
to open the standart email program ...,
 
Back
Top