delphi 强行关闭进程

uses
  Tlhelp32;

function KillTask(ATask: string): Boolean;
var
  Loop: Boolean;
  hd: THandle;
  pe: TProcessEntry32;
begin
  Result := False;
  hd := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  pe.dwSize := Sizeof(pe);
  Loop := Process32First(hd,pe);
  while Loop  do
  begin
    if ((UpperCase(ExtractFileName(pe.szExeFile)) = UpperCase(ATask))
    or (UpperCase(pe.szExeFile) = UpperCase(ATask))) then
       Result := TerminateProcess(OpenProcess($0001,False,pe.th32ProcessID),0);
    Loop := Process32Next(hd,pe);
  end;
  CloseHandle(hd);
end;

  

posted @ 2016-11-25 23:30  伯通心智  阅读(730)  评论(0编辑  收藏  举报