本文整理自网络,侵删。
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;
相关阅读 >>
Delphi�⒆执�传入到windows目前窗口cursor所在位置
Delphi中datetimepicker控件同时输入日期和时间
Delphi 用正则表达式获取指定的字符串续取出所有符合要求的字符串
Delphi xe6、xe5、xe7在android创建快捷方式
更多相关阅读请进入《Delphi》频道 >>