首页 > 代码库 > delphi 强行关闭进程

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;

  

delphi 强行关闭进程