Process class and some small demo code

Hi

I just found some simple code that I have used in my previous application related to process in a windows application.

Many a time we want to run some external application from our windows application. To do that we need top start the process for that application. Lets say we want to start the WordPad application from our window application.

Process proc = new Process();

proc.StartInfo.FileName = @"Wordpad.exe";

proc.StartInfo.Arguments = "";

proc.Start();

This will start the word pad application in the system. If we give provide an web address as the file name then the default browser will open with the given URL.

Another trick is to find all the programs that are running in the local machine. The code is simple and self-explanatory.

foreach ( Process p in Process.GetProcesses(System.Environment.MachineName) )

{

if( p.MainWindowHandle != IntPtr.Zero)

{

Console.WriteLine( p );

}

}

Do not forget to import the System.Diagnostics namespace for this code to work properly

Thanks
Vikram


Share this post   Email it |  digg it! |  reddit! |  bookmark it!

Feedback

Please post your comments:

Name:  
Email (optional): Your email address will not be posted.
URL (optional):
Comments: HTML will be ignored, URLs will be converted to hyperlinks  
Enter the text you see in the box:
 
Copyright © 2006 - 2009 Vikram Lakhotia