SIGN UP MEMBER LOGIN:    
ARTICLE

Operations on Your Computer Processes

Posted by Ghanashyam Nayak Articles | Operating Systems January 06, 2012
This program will help you to perform operations on your computer processes like add new task, delete new task, find process etc.
Reader Level:
Download Files:
 

This article is about the processes in your computer & operations on them.
 
You can use the Process class in the System.Diagnosis namespace.
 
using System.Diagnostics;
 

Using the Process.GetProcesses() method it will get all the processes in your computer as an array of Processes....
 
Process[] prc=Process.GetProcesses();
 
Every time it will first clear the ListBox otherwise it will append the processes to the ListBox. So we need to clear the ListBox before adding the processes in the ListBox.
 
lbProcess.Items.Clear();
 
Now I create one process called Load_Process & it will load all the processes currently running in the computer and display them in the ListBox.
 
 
private void Load_Process()
 {
     lbProcess.Items.Clear();
    
try
 
    {
         foreach (var item in prc)
         {
             lbProcess.Items.Add(item.ProcessName);
         }
     }  
     catch (Exception e)
     { 
         MessageBox.Show(e.Message.ToString());
     }
 }

 
See The following Image 

Load_Process.jpg

When the user clicks on the refresh button it will load all the process again into the ListBox.
 
 
private void btnRefresh_Click(object sender, EventArgs e)
 {
     Load_Process();
 }
 

After selecting a particular process it will kill that selected particular process from the list & then again it will load all the processes in the ListBox.
 
 
private void btnEndTask_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Are You Sure Want To Kill..?", "Kill Process", MessageBoxButtons.OK) == System.Windows.Forms.DialogResult.OK)
     {
         prc[lbProcess.SelectedIndex].Kill();
         lbProcess.SelectedIndex = 0;
         Load_Process();
 }

 
See the Following Image

EndTask_Process.jpg

If the user wants to add a new task then by clicking the NewTask button it will start the new process & then it will load all the processes into ListBox, so that it will add that new process in the list.
 
 
private void btnNewTask_Click(object sender, EventArgs e)
 {
     OpenFileDialog ofd = new OpenFileDialog();
     ofd.ShowDialog();
     Process.Start(ofd.FileName.ToString());
     Load_Process();
 }
 

See the Following Image :

NewTask_Process.jpg

After adding the new task in the list it will display in the ListBox process.
 
See the Following Image :


ListNewTask_Process.jpg

If the user wants to find a particular process from the list then it will find that specific process name from the list & if it will find then it will select that process in the ListBox.
 
You can find the process name as simple search using FindString method & find Exact match using FindStringExact method.
 
 
private void btnFind_Click(object sender, EventArgs e)
 {
     if (cbFindExact.Checked)
     {
         for (int i = 0; i < lbProcess.Items.Count; i++)
         {
             if (!(lbProcess.FindStringExact(txtFind.Text) == -1))
             {
                 lbProcess.SelectedIndex = lbProcess.FindStringExact(txtFind.Text);
                 break;
             }
            
else
 
            {
                 MessageBox.Show("No Process In List....");
                 break;
             }
         }
     }
    
else
 
    {
         for (int i = 0; i < lbProcess.Items.Count; i++)
         {
             if (!(lbProcess.FindString(txtFind.Text) == -1))
             {
                 lbProcess.SelectedIndex = lbProcess.FindString(txtFind.Text);
                 break;
             }
            
else
 
            {
                 MessageBox.Show("No Process In List....");
                 break;
             }
         }
     }
 }

 
See the following Image of Simple Search :


Find_Process.jpg

See the following Image Of Find Exact Match :

FindExact_Process.jpg

If the process does not find an exact match then it will display the error message to user.
 
See following Image :

NoFind_Process.jpg

This way you can perform all these operations of processes...

Login to add your contents and source code to this article
share this article :
post comment
 

Thank You So Much Akshay & Akash..

Posted by Ghanashyam Nayak Jan 08, 2012

Thanks Arjun...

Posted by Ghanashyam Nayak Jan 08, 2012

Thank You So Much Jimmy...

Posted by Ghanashyam Nayak Jan 08, 2012

Really a fantastic article..thoroughly described..great

Posted by Akash Ahlawat Jan 07, 2012

Really most desirable for this article

Posted by Arjun Panwar Jan 07, 2012
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor