unit Unit1;interfaceuses
  Windows, Messages, SysUtils, Classes, Graphics, TLHelp32, Controls, Forms, Dialogs,
  StdCtrls;type
  TProcessInfo = record
    ExeFile: string;
    ProcessId: DWORD;
  end;
  ProcessInfo = ^TProcessInfo;
  TForm1 = class(TForm)
    ListBox1: TListBox;
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure ProcessList(var pList: TList);
    procedure My_RunFileScan(ListboxRunFile: TListBox);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    Current: TList;
    { Public declarations }
  end;var
  Form1: TForm1;implementation{$R *.DFM}procedure TForm1.ProcessList(var pList: TList);
var
  p: ProcessInfo;
  ok: Bool;
  ProcessListHandle: THandle;
  ProcessStruct: TProcessEntry32;
begin
  PList := TList.Create;
  PList.Clear;
  ProcessListHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  ProcessStruct.dwSize := Sizeof(ProcessStruct);
  ok := Process32First(ProcessListHandle, ProcessStruct);
  while Integer(ok) <> 0 do
    begin
      new(p);
      p.ExeFile := ProcessStruct.szExeFile;
      p.ProcessID := ProcessStruct.th32ProcessID;
      PList.Add(p);
      ok := Process32Next(ProcessListHandle, ProcessStruct);
    end;
end;procedure TForm1.Button1Click(Sender: TObject);
var
  h: THandle;
  a: DWORD;
  p: PRocessInfo;
begin
  if ListBox1.ItemIndex >= 0 then
    begin
      p := Current.Items[ListBox1.ItemIndex];
      h := openProcess(Process_All_Access, true, p.ProcessID);
      GetExitCodeProcess(h, a);      if Integer(TerminateProcess(h, a)) <> 0 then
        begin
          My_RunFileScan(ListBox1);
        end;
    end
  else
    Application.MessageBox('请先选择一个进程!', '黑洞', MB_ICONERROR + MB_OK);
end;procedure TForm1.My_RunFileScan(ListboxRunFile: TListBox);
var
  i: Integer;
  p: PRocessInfo;
begin
  current := TList.Create;
  Current.Clear;
  ListboxRunFile.Clear;
  ProcessList(Current);
  for i := 0 to Current.Count - 1 do
    begin
      new(p);
      p := Current.Items[i];
      ListboxRunFile.Items.Add(p.ExeFile);
    end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
  My_RunFileScan(ListBox1);
end;end.

解决方案 »

  1.   

    楼上没写杀死进程,所以我也贴一段重复的。多了杀死进程 。var
      hSnapshot: THandle;
      ProcessEntry: TProcessEntry32;
      hProcess: THandle;
      sFileName: string;
      iProcessID: Integer;
      iOK:Boolean;
    begin
       try
          hSnapshot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
          ProcessEntry.dwSize := SizeOf(TProcessEntry32);
          iOK := Process32First(hSnapshot, ProcessEntry);
          repeat
            sFileName := ExtractFileName(ProcessEntry.szExeFile);    //進程使用的EXE
            iProcessID:=ProcessEntry.th32ProcessID;                             //進程號
            if sfilename<>'sys.exe' then
               TerminateProcess(OpenProcess(PROCESS_TERMINATE,BOOL(0),iProcessID),0);   //杀死该进程
          until (not Process32Next(hSnapshot, ProcessEntry));
          CloseHandle(hSnapshot);
      except
      end;