Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
const
TH32CS_SNAPPROCESS = $00000002;
type
PPROCESSENTRY32 = ^TPROCESSENTRY32;
TPROCESSENTRY32 = packed record
dwSize,
cntUsage,
th32ProcessID,
th32DefaultHeapID,
th32ModuleID,
cntThreads,
th32ParentProcessID: DWORD;
pcPriClassBase: LongInt;
dwFlags: DWORD;
szExeFile: array[0..MAX_PATH-1] of char;
end;
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
function CreateToolhelp32Snapshot(dwFlags, th32ProcessID: DWORD): THandle; stdcall; external 'kernel32.dll' name 'CreateToolhelp32Snapshot';
function Process32First(hSnapshot: THandle; const lppe: TPROCESSENTRY32): boolean; stdcall;external 'kernel32.dll' name 'Process32First';
function Process32Next(hSnapshot: THandle; const lppe: TPROCESSENTRY32): boolean; stdcall;external 'kernel32.dll' name 'Process32Next';
implementation
{$R *.DFM}
procedure TForm1.Button1Click(Sender: TObject);
var
snap: THandle;
tmp: string;
me: TPROCESSENTRY32;
r: integer;
begin
snap := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
me.dwSize := SizeOf(TPROCESSENTRY32);
if Process32First(snap,me)=true then ShowMessage('ok');
while Process32Next(snap,me)=true do
begin
tmp := '';
r := 0;
while me.szExeFile[r]<>#0 do
begin
tmp := tmp + me.szExeFile[r];
inc(r);
end;
MessageBox(0,pchar(tmp),'hehe:)',0);
end;
end;
end.
;)