delphi GetExplorerPID获取系统explorer.exe进程ID  
官方Delphi 学习QQ群: 682628230(三千人)
频道

delphi GetExplorerPID获取系统explorer.exe进程ID


//单元文件 TLHelp32   获取explorer.exe进程ID 同样也可以获取任何进程ID

function GetExplorerPID(const AExeName: string): int64;

var

ProcessName : string; //进程名

ProcessID : integer; //进程表示符

i : integer;

ContinueLoop:BOOL;

FSnapshotHandle:THandle; //进程快照句柄

FProcessEntry32:TProcessEntry32; //进程入口的结构体信息

begin

FSnapshotHandle:=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0); //创建一个进程快照

FProcessEntry32.dwSize:=Sizeof(FProcessEntry32);

ContinueLoop:=Process32First(FSnapshotHandle,FProcessEntry32); //得到系统中第一个进程

//循环例举 www.delphitop.com 

while ContinueLoop do

begin

ProcessName := FProcessEntry32.szExeFile;

ProcessID := FProcessEntry32.th32ProcessID;

//result :=result+inttostr(ProcessID)+ProcessName;

if pos(UpperCase(ProcessName),UpperCase(AExeName))>0 then

begin

result :=ProcessID;

break;

end

else

begin

result :=0;

end;

ContinueLoop:=Process32Next(FSnapshotHandle,FProcessEntry32);

end;

end;


推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.043554067611694 seconds