关于结束进程的语句

查找进程的ID:

function GetProcessID(AExeName :string):DWORD;
const
  PROCESS_TERMINATE = $0001;
var
  SnapShot_Handle :THandle;
  _ProcessEntry32 :TProcessEntry32;
  _IsFound :Boolean;
begin
  Result := 0;
  if Trim(AExeName) <> '' then
  begin
    _ProcessEntry32.dwSize := SizeOf(TProcessEntry32);
    SnapShot_Handle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    _IsFound := Process32First(SnapShot_Handle, _ProcessEntry32);
    while _IsFound do
    begin
      if (UpperCase(ExtractFileName(_ProcessEntry32.szExeFile))=UpperCase(AExeName)) or
          (UpperCase(_ProcessEntry32.szExeFile) = UpperCase(AExeName)) then
        Result := _ProcessEntry32.th32ProcessID;

      _IsFound := Process32Next(SnapShot_Handle, _ProcessEntry32);
    end;
  end;
end;

 

 

结束进程函数:

function KillProcess(AProcessID :DWORD):Boolean;
var
  Process_Handle :THandle;
begin
  Result := False;
  if AProcessID <> 0 then
  begin
    Process_Handle := OpenProcess(PROCESS_TERMINATE, False, AProcessID);
    if Process_Handle <> 0 then
    begin
      TerminateProcess(Process_Handle, 0);
      CloseHandle(Process_Handle);
      Result := True;
    end;
  end;
end;

你可能感兴趣的:(关于结束进程的语句)