Hallo Hagen,
ist gar keine so kranke Idee. Hab ich auch schon gemacht.
Diese Procedure screibt alle Prozesse in ein TListView:
procedure TMainForm.RefreshProcessList;
var
i: Integer;
Ignore: Boolean;
Item: TListItem;
ModuleCount: Cardinal;
Modules: array[0…512] of DWord;
Process: THandle;
ProcessName: array[0…512] of Char;
ProcessNameStr: string;
Processes: array[0…512] of DWord;
Used: Cardinal;
begin
lstProcesses.Items.Clear;
Win32Check(EnumProcesses(@Processes[0], sizeof(Processes), Used));
for i := 0 to (Used div sizeof(DWord)) - 1 do begin
Ignore := False;
Process := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ,
False, Processes[i]);
if Process = 0 then begin
ProcessNameStr := ‚unknown‘;
end else begin
try
Win32Check(EnumProcessModules(Process, @Modules[0], sizeof(Modules[0]),
ModuleCount));
GetModuleBaseName(Process, Modules[0], ProcessName,
sizeof(ProcessName));
ProcessNameStr := string(ProcessName);
CloseHandle(Process);
except
CloseHandle(Process);
Ignore := True;
end;
end;
if not Ignore then begin
Item := lstProcesses.Items.Add;
Item.Caption := ProcessNameStr;
Item.SubItems.Add(IntToStr(Processes[i]));
end;
end;
end;
Und nun schaun wir mal ob IE noch läuft, wenn ja kill ihn!
procedure TMainForm.killIexplore;
var
i: Integer;
Process: THandle;
ProcessId: DWord;
begin
RefreshProcessList;
Application.ProcessMessages;
for i := lstProcesses.Items.Count -1 downto 0 do
begin
// lstProcesses: TListView;
if UpperCase(lstProcesses.Items.Item[i].Caption) = ‚IEXPLORE.EXE‘ Then
begin
ProcessId := StrToInt(lstProcesses.Items.Item[i].SubItems[0]);
Process := OpenProcess(PROCESS_TERMINATE, False, ProcessId);
if Process = 0 then exit;
TerminateProcess(Process, 1);
CloseHandle(Process);
end;
end;
end;
Übrigens muss man nicht unbedingt ein TListView benutzen, man kann aber schön alle Prozesse sehen.
Viele Grüße
Manfred