uses Tlhelp32;
function KillProc(ExeFileName:string; kill:boolean):Integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;//是否继续遍历
FSnapshotHandle: THandle; //用于获得进程列表
FProcessEntry32: TProcessEntry32;//用于查找进程
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);//获得系统进程列表
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);//在调用Process32First API之前,需要初始化lppe记录的大小
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);//将进程列表的第一个进程信息读入ppe记录中
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName))
or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
if kill = true then
Result := Integer(TerminateProcess(OpenProcess(
PROCESS_TERMINATE, BOOL(0),
FProcessEntry32.th32ProcessID), 0))
else
Result:=1;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);//将进程列表的下一个进程信息读入lppe记录中
end;
CloseHandle(FSnapshotHandle);
end;
Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号
执行时间: 0.051959037780762 seconds