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;
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;
TProcessEntry32
CreateToolHelp32Snapshot
TH32CS_SNAPPROCESS
Process32First
Process32Next
这几个都是UnDeclared, 找不到它们所在的Unit,如何处理,谢谢
引用 TlHelp32