Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Processes List

Posted on 2004-11-11
5
Medium Priority
?
178 Views
Last Modified: 2012-05-05
Hello,

I have a PopupMenu,

I need to know how to at runtime make this like have a menu of all running exe's
e.g

My Menu > Running Processes > explorer.exe
                                                notepad.exe
                                                someapp.exe

But also when I click one one lets say 'notepad.exe' it will kill that task.

Needs to work on Windows XP
0
Comment
Question by:-Karamja-
  • 3
5 Comments
 
LVL 22

Expert Comment

by:Mohammed Nasman
ID: 12559803
Hello

Download JCL library, and look at jclsysinfo unit, there's function called RunningProcessesList, which will return all the Processes running, its work on win 9x to win XP, and there are some samples included in with JCL which give you current process and ability to kill any process

you can download it from here
http://sourceforge.net/projects/jcl

Also look at Madshi Kernal
www.madshi.net
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12559918
I'm coding one right now for you...
0
 
LVL 5

Accepted Solution

by:
Hypoviax earned 2000 total points
ID: 12560370
Ok here is a complete working version i coded and tested in XP:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus,Tlhelp32,ComCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    PopupMenu1: TPopupMenu;
    sdfsd1: TMenuItem;
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);


  private
    procedure findprocesses ;
    procedure MenuClick(Sender: TObject);
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}



function KillTask(ExeFileName: string): integer;
 const  //Kills a process by exename
 PROCESS_TERMINATE=$0001;
 var
 ContinueLoop: BOOLEAN;
 FSnapshotHandle: THandle;
 FProcessEntry32: TProcessEntry32;
             begin
              //      result := 0;
                   FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
                   FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
                   ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);

 while integer(ContinueLoop) <> 0 do
 begin
             if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName))
             or (UpperCase(FProcessEntry32.szExeFile) =
             UpperCase(ExeFileName))) then
             Result := Integer(TerminateProcess(OpenProcess(PROCESS_TERMINATE, BOOL(0),FProcessEntry32.th32ProcessID), 0));
                ContinueLoop := Process32Next(FSnapshotHandle,
              FProcessEntry32);
 end;
 CloseHandle(FSnapshotHandle);
end;



function StripChars(const Value: string; SkipChars: string): string;
var
  X,y: Integer;
  Max,maxskips: Integer;
  CurrentChr,CurrentSkip:String;
  foundskipchar:boolean;
begin
max:=length(value);
maxskips:=length(SkipChars);
   For X:=1 to max do
   begin
   foundskipchar:=false;
   CurrentChr:=copy(value,x,1);
    For Y:=0 to maxskips do
      begin
         CurrentSkip:=copy(skipchars,y,1);
        if CurrentChr=CurrentSkip then
          begin
              foundskipchar:=true;
          end;
      end;
      if foundskipchar<>true then
        begin
          result:=result+CurrentChr
        end;
   end;
end;

procedure TForm1.MenuClick(Sender: TObject); //this occurs when the click the item on the popupmenu
var
  tmpMenuItem : TMenuItem;
  process:string;
begin
  tmpMenuItem := Sender As TMenuItem;
  //for some reason we need to get rid of the & symbol so:
  process:=stripchars(tmpmenuitem.Caption,'&');
  killtask(process);     //kill it
end;

procedure tform1.findprocesses ; //adds to the popupmenu
const
 PROCESS_TERMINATE=$0001;
 var
 ContinueLoop: BOOLEAN;
 FSnapshotHandle: THandle;
 FProcessEntry32: TProcessEntry32;
 menuitem:Tmenuitem;
             begin

     popupmenu1.Items.Clear;     //clear previous list
                   FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
                   FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
                   ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);

 while integer(ContinueLoop) <> 0 do
 begin    //add to list
 popupmenu1.items.Add(NewItem(FProcessEntry32.szExeFile, TextToShortCut(''), False, True, MenuClick, 0, 'Item1'));
  ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
end;
 CloseHandle(FSnapshotHandle);
end;

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin //this can be whereever you want it to be.
if button=mbright then //right click on form
begin
findprocesses; //create and update list
popupmenu1.Popup(form1.left+100,form1.Top-100); //popup someplace
end;
 end;



end.

Best Regards,

Hypoviax
0
 
LVL 5

Expert Comment

by:Hypoviax
ID: 12560458
Thanks,

I hope it is what you wanted

Regards,

Hypoviax
0
 
LVL 2

Author Comment

by:-Karamja-
ID: 12560497
It is thanks ;)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month14 days, 5 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question