监视进程并结束进程在很多地方都用到这里借前人的经验写了个小例子:
以QQ的进程qq.exe为例
关键代码如下:
function CheckTask(ExeFileName: string): Boolean; const PROCESS_TERMINATE=$0001; var ContinueLoop: BOOL; FSnapshotHandle: THandle; FProcessEntry32: TProcessEntry32; begin result := False; FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); FProcessEntry32.dwSize := Sizeof(FProcessEntry32); ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32); while integer(ContinueLoop) <> 0 do begin if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =UpperCase(ExeFileName))) then result := True; ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32); end; end; function KillTask(ExeFileName:string):integer; procedure TForm1.Button1Click(Sender: TObject); |
function CheckTask
function KillTask这两个函数在网上找的,这个例子一看就懂的,下面给出测试效果: