Delphi监视进程并结束进程
来源:互联网 发布:电脑摄像头软件 编辑:程序博客网 时间:2024/04/28 08:54
以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;
const
PROCESS_TERMINATE = $0001;
var
ContinueLoop: BOOLean;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
Result := 0;
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 := Integer(TerminateProcess(
OpenProcess(PROCESS_TERMINATE,
BOOL(0),
FProcessEntry32.th32ProcessID),
0));
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if CheckTask(’qq.exe’)=true then
KillTask(’qq.exe’)
else
Label1.Caption:=’进程不存在,监视中...’;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if CheckTask(’qq.exe’)=true then
Label1.Caption:=’进程正在运行中...’
else
Label1.Caption:=’进程不存在,监视中...’;
end;
转自:http://www.cnblogs.com/qq528/archive/2008/12/03/1346916.html
- Delphi监视进程并结束进程
- delphi 枚举进程,结束进程
- delphi中结束进程
- delphi 结束进程
- Delphi结束进程模块
- Delphi结束指定进程...
- Delphi结束指定进程
- 查找并结束进程
- 遍历并监视,重新启动进程
- Delphi根据进程PID等待进程结束或者结束进程
- 转:delphi中结束进程
- delphi查找和结束进程
- delphi查找和结束进程
- Delphi结束指定进程EndProcess
- C#获取进程、查找并结束进程
- 启动进程并等待进程结束
- 根据进程名,查找并结束进程
- windows 枚举进程,并结束进程
- delphi字符串
- IDEA工程转为Myeclipse工程
- 无法登陆到域
- 如何在excel里同时插入多个对象(PDF\WORD\EXCEL\图片等)
- SDN和网络虚拟化
- Delphi监视进程并结束进程
- 关于继承中两义性问题
- Exception ACCESS_VIOLATION 解决方案
- Spring mvc 3.0与2.5的改进
- 网络安全软件FileAudit数据库使用方法
- 【解决windows7系统开机硬盘自检方法】
- java中方法drawImage()的参数详细解释
- 码流源分辨率和不同输出分辨率的效果
- linux scp传文件