/*This program lists all of the current processes on your machine.
*and gives you the option to terminate them
*/

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using Microsoft.Win32;
using System.IO;
using System.Diagnostics;
using System.Resources;
//^ Headers

namespace Process_Manager
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Process myProcess = new Process();
            //Declare process
            txtMachine.Text = System.Environment.MachineName.ToString();
            //set the machine name to textbox
        }

        private void FillList(string MachineName)
        {
            Process[] Prc;
            ListViewItem lvwP;

            Cursor.Current = Cursors.WaitCursor;
            //Set cusrsor as wait

            try
            {
                lvwProcesses.Items.Clear();//Clear the items
                Prc = Process.GetProcesses(MachineName.ToString());//Get the process's of our machine

                foreach (Process Prcs in Prc)
                {
                    lvwP = lvwProcesses.Items.Add(Prcs.ProcessName.ToUpper());
                    if (MachineName != System.Environment.MachineName)
                    {
                        //try to add
                        lvwP.SubItems.Add("Unavailable...");
                        lvwP.SubItems.Add("Unavailable...");
                        lvwP.SubItems.Add(Prcs.Id.ToString());
                    }
                    else
                    {
                        //if failed try this
                        lvwP.SubItems.Add(Prcs.MainWindowTitle);
                        lvwP.SubItems.Add(Prcs.Responding.ToString());
                        lvwP.SubItems.Add(Prcs.Id.ToString());
                    }
                }
            }
            catch
            {
                lvwProcesses.Items.Add("Error enumerating items...");//error
            }

            Cursor.Current = Cursors.Default;//defualt cursor
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            FillList(txtMachine.Text);//fill list
        }

        private void cmdRefresh_Click(object sender, EventArgs e)
        {
            FillList(txtMachine.Text);//refresh
        }
    }
}

/* This could be easily expanded to sstart process's to.
*using  somthing like Process.Start(path);
*Enjoy!
*/
4
Contributors
3
Replies
5
Views
11 Years
Discussion Span
Last Post by VinhBrao
0

Thats the process manager....
You've before compiling this code to adjust namespace names or create the windows application with Process_Manager name
second to add in the form ListView control with name lvwProcesses, TextBox control with name txtMachine and Button control with name cmdRefersh and give in click event handler this method cmdRefersh_Click
It will work!

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.