当前位置:编程问答 > Delphi >

关于DELPHI的TPROCESSENTRY32

问题:function KillTask(ExeFileName: string): integer;
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
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;
end;

哪位高手帮我解释一下这个程序?谢谢
答案:function KillTask(ExeFileName: string): integer; //杀进程函数
const
PROCESS_TERMINATE=$0001;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
result := 0;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
//取得系统快照
FProcessEntry32.dwSize := Sizeof(FProcessEntry32);
//循环例举,如果到达最后,则退出loop
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),
//调用terminateprocess结束符合的进程项
FProcessEntry32.th32ProcessID), 0));
ContinueLoop := Process32Next(FSnapshotHandle,FProcessEntry32);
end;
end;

ContinueLoop := Process32First(FSnapshotHandle,FProcessEntry32);
//这一句是从进程链中,取出一个到FProcessEntry32结构中,然后
在这个结构中取得进程名。至于FProcessEntry32,你用按下ctrl同时在这个上面鼠标点下,可以看到它的详细定义。
身吗

上一个:关于delphi的 trackbar 属性!
下一个:Delphi 如何创建动态菜单?

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,