uses Tlhelp32;
var
ProcArr: array of TProcessEntry32;
procedure EnumProcess(pNameList, PidList: TStrings);
var
hProcess: THandle;
Find: Boolean;
Proc: TProcessEntry32;
i: DWORD;
begin
try
hProcess := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
Proc.dwSize := SizeOf(Proc);
Find := Process32First(hProcess, Proc);
i := 0;
while Find do
begin
SetLength(ProcArr, i + 1);
ProcArr[i] := Proc;
inc(i);
pNameList.Add(Proc.szExeFile);
PidList.Add(inttostr(Proc.th32ProcessID));
Find := Process32Next(hProcess, Proc);
end;
finally
CloseHandle(hProcess);
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
const
ProcName = 'Goghost.exe';
var
PnList, PidList: TStringList;
i: DWORD;
begin
try
PnList := TStringList.Create;
PidList := TStringList.Create;
PnList.Clear;
PidList.Clear;
EnumProcess(PnList, PidList);
for i := Low(ProcArr) to High(ProcArr) do
if SameText(ProcArr[i].szExeFile, ProcName) then
TerminateProcess(OpenProcess(PROCESS_TERMINATE, False, Procarr[i].th32ProcessID), 0);
finally
FreeAndNil(PnList);
FreeAndNil(PidList);
end;
end;
遍历结束指定进程演示
最新推荐文章于 2020-06-23 18:36:00 发布