Process Manager

tayspen 0 Tallied Votes 166 Views Share

Shows how to create a simple 'Process Manager'. and control processes

/*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!
*/
HLA91 -3 Junior Poster

Tried it but didnt work error occured

Ramy Mahrous 401 Postaholic Featured Poster

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!

VinhBrao 0 Newbie Poster

the codes are error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.