Dieser Code ist ein einfacher, aber gut geeigneter Prozess Viewer mit einer Kill Funktion.
Die ListView benötigt 5 Einträge: Nr; ProzessID; Path; Thread; ParentID; ClassBase
Das Beispiel ist gut für die erweiterte Programmierung geeignet, im Thema Prozesse.
uses ComCtrls, Tlhelp32
//
Function HexToInt(s:string):integer;
var Num,k:integer;
begin
Num:=0;
for k:=1 to length(s) do
begin
if (s[k]='F')or(s[k]='f') then Num:=Num*16+15;
if (s[k]='E')or(s[k]='e') then Num:=Num*16+14;
if (s[k]='D')or(s[k]='d') then Num:=Num*16+13;
if (s[k]='C')or(s[k]='c') then Num:=Num*16+12;
if (s[k]='B')or(s[k]='b') then Num:=Num*16+11;
if (s[k]='A')or(s[k]='a') then Num:=Num*16+10;
if (s[k]='9') then Num:=Num*16+9;
if (s[k]='8') then Num:=Num*16+8;
if (s[k]='7') then Num:=Num*16+7;
if (s[k]='6') then Num:=Num*16+6;
if (s[k]='5') then Num:=Num*16+5;
if (s[k]='4') then Num:=Num*16+4;
if (s[k]='3') then Num:=Num*16+3;
if (s[k]='2') then Num:=Num*16+2;
if (s[k]='1') then Num:=Num*16+1;
if (s[k]='0') then Num:=Num*16+0;
end;
result:=Num;
end;
procedure treeparnum;
begin
//
end;
procedure treeparhandle;
begin
//form1.ListView1.Arrange(arAlignTop);
end;
procedure treeparname;
begin
//form1.ListView1.Arrange(arAlignTop);
end;
procedure treeparshow;
begin
//form1.ListView1.Arrange(arAlignTop);
end;
procedure TForm1.ListView1ColumnClick(Sender: TObject;Column: TListColumn);
begin
if Column.Index=0 then
treeparnum
else
if Column.Index=1 then
treeparhandle
else
if Column.Index=2 then
treeparname
else
treeparshow;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1Click(nil);
end;
Prozesse aktualisieren :
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;s:string;FSnapshotHandle:THandle;
FProcessEntry32: TProcessEntry32;
ContinueLoop:boolean;
begin
i:=1;
ListView1.Items.Clear;
FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
while integer(ContinueLoop) <> 0 do
begin
s:=inttostr(i);ListView1.Items.Add.Caption:=s;
s:=inttohex(FProcessEntry32.th32ProcessID,8);
ListView1.Items.Item[ListView1.Items.Count-1].SubItems.Add(s);
s:=FProcessEntry32.szExeFile;
ListView1.Items.Item[ListView1.Items.Count-1].SubItems.Add(s);
s:=inttohex(FProcessEntry32.cntThreads,4);
ListView1.Items.Item[ListView1.Items.Count-1].SubItems.Add(s);
s:=inttohex(FProcessEntry32.th32ParentProcessID,4);
ListView1.Items.Item[ListView1.Items.Count-1].SubItems.Add(s);
s:=inttohex(FProcessEntry32.pcPriClassBase,4);
ListView1.Items.Item[ListView1.Items.Count-1].SubItems.Add(s);
i:=i+1;
ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
Prozess terminieren :
procedure TForm1.Button2Click(Sender: TObject);
var
HProsses:THandle;
ProssesID:DWord;
ExitCodes:DWord;
begin
ProssesID:=hextoint(ListView1.Selected.SubItems[0]);
HProsses:=openprocess(PROCESS_ALL_ACCESS,false,ProssesID);
if not GetExitCodeProcess(HProsses,ExitCodes) then
Messagebbox(handle,'Not ExitCode','ERROR',0);
if (TerminateProcess(HProsses,ExitCodes)) then
ListView1.Selected.Delete
else
MessageBox(handle,'Not Termined','ERROR',0);
end;
Keine Kommentare:
Kommentar veröffentlichen