- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
delphi 查看指定文件是否在进程列表中
uses tlhelp32;
// 查看指定文件是否在进程列表中
function FileInProcessList(strFileName: string): Boolean;
var
pe32: PROCESSENTRY32;
me32: MODULEENTRY32;
hSnapShot: THandle;
bFlag: Boolean;
hModuleSnap: THandle;
strTemp: string;
begin
Result := False;
ZeroMemory(@pe32, sizeof(pe32));
pe32.dwSize := SizeOf(pe32);
hSnapShot := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if hSnapShot = 0 then exit;
bFlag := Process32First(hSnapShot, pe32);
while bFlag do
begin
if UpperCase(ExtractFileName(strFileName))= UpperCase(ExtractFileName(pe32.szExeFile)) then
begin
hModuleSnap := CreateToolhelp32Snapshot(TH32CS_SNAPALL, pe32.th32ProcessID);
if hModuleSnap = INVALID_HANDLE_VALUE then
strTemp := string(pe32.szExeFile)
else
begin
ZeroMemory(@me32, sizeof(me32));
me32.dwSize := sizeof(me32);
if Module32First(hModuleSnap, me32) then
strTemp := string(me32.szExePath);
end;
CloseHandle(hModuleSnap);
if UpperCase(strTemp) = UpperCase(strFileName) then
begin
Result := True;
exit;
end;
end;
bFlag := Process32Next(hSnapShot, pe32);
end;
CloseHandle(hSnapShot);
end;