function TForm1.GetProID(ProName:String):int64;
var p: pProcessInfo;
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
tmp:String;
begin
result:=0;
try
Up(ProName);
FSnapshotHandle := CreateToolHelp32Snapshot(TH32CS_SNAPPROCESS,0);
FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
while ContinueLoop do
begin
New(p);
tmp:=FProcessEntry32.szExeFile;
Up(tmp);
if ProName=tmp then
begin
result:= FProcessEntry32.th32ProcessID;
break;
end;
ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);
end;
except
end;
end;
procedure TForm1.KillProByName(proname:String);
var
HProcess: Thandle;
uExitCode: int64;
ID:int64;
begin
try
ID := GetProID(proname);
if ID>0 then
hProcess := openprocess(PROCESS_TERMINATE,FALSE,ID);
if TerminateProcess(hProcess,3838) then
begin
//删除进程成功
end;
except
end;
end;