Friday, August 03, 2007

how to invoke a new application from .net

how to invoke a new application from .net


public enum OpenMode

{
Mode_HIDE = 0,
Mode_SHOWNORMAL = 1,
Mode_SHOWMINIMIZED = 2,
Mode_SHOWMAXIMIZED = 3,
Mode_MAXIMIZE = 3,
Mode_SHOWNOACTIVATE = 4,
Mode_SHOW = 5,
Mode_MINIMIZE = 6,
Mode_SHOWMINNOACTIVE = 7,
Mode_SHOWNA = 8,
Mode_RESTORE = 9,
Mode_SHOWDEFAULT = 10,
Mode_FORCEMINIMIZE = 11,
}

[DllImport("shell32.dll")]
static extern IntPtr ShellExecute(IntPtr hwnd, string lpOperation, string lpFile, string lpParameters, string lpDirectory, OpenMode opnMode);


and use this method to call exes




//ShellExecute(this.Handle,"open",textBox1.Text,"","",ShowCommands.SW_MAXIMIZE);
// ShellExecute( IntPtr.Zero, "open", "mailto:support@microsoft.com", "", "", ShowCommands.SW_SHOWNOACTIVATE );
//ShellExecute( this.Handle, "open", textBox1.Text, "", "", ShowCommands.SW_SHOWNOACTIVATE );


and replace textBox1.Text with proper exename

1 comment:

Lcosmos said...

Hi Pradip!
Its nice to see you blogging about the techie things,here.
Doesn't this post tend to use unmangaed code and revoke the monster of DLL hell???
I think there is pretty much better way of doing this.

How about using System.Diagnostics.Process???