function getProcessesWithFilter(filter, sortfunc) local SL=createStringlist() getProcesslist(SL) local wndPid2Caption = getWindowlist() local procs = {} for i=0,SL.Count-1 do local itm = {} local pid,exename = SL[i]:match"^(%x+)[-%s]*(.-)$" if pid then -- populate some common property for pid itm.pid = tonumber(pid,16) itm.exename = exename itm.order = i/SL.Count itm.caption = wndPid2Caption[itm.pid] or '--' procs[1+#procs] = itm procs[pid:upper()] = itm -- saved a hex-pid -> itm entry end end SL.Destroy() if filter then -- may remove itm not met condition for i=#procs,1,-1 do if filter(procs[i],procs) then table.remove(procs,i) end end end if not sortfunc then -- how to sort, default by order sortfunc = function(a,b) return a.order>b.order end end-- now lesser index match more recent process, so -- to show first(upper position) in a listbox, as eg. table.sort(procs, sortfunc) return procs end -- test #1 function uncaseContain(str,sub) return str:lower():find(sub:lower(),1,true)-- find plain text end local procs1 = getProcessesWithFilter(function(p,ps) if uncaseContain( p.exename,"chrome" ) then return false -- keep else return true -- remove end end) print("List #1") for i=1,#procs1 do local p = procs1[i] print(p.pid, p.exename, p.caption, p.dll) end -- test #2 function HasNameAndDll(name_list, dll_list) name_list = name_list or {'chrome','firefox','explorer'} -- sample dll_list = dll_list or {'flash','user32','unity'} if type(name_list)=='string' then name_list = {name_list} end if type(dll_list)=='string' then dll_list = {dll_list} end return function(p,ps) -- filter function factory local m for i=1,#name_list do local nm = name_list[i]:lower() if uncaseContain( p.exename, nm ) then m = m or enumModules(p.pid) -- should only call once per pid, and only if needed for j=1,#dll_list do for k = 1,#m do if uncaseContain( m[k].Name, dll_list[j] ) then p.dll = m[k].Name -- add more property to the pid item return false -- keep end end end end end return true -- no match, remove end end local procs2 = getProcessesWithFilter( HasNameAndDll("chrome","inet") ) print("List #2") for i=1,#procs2 do local p = procs2[i] print(p.pid, p.exename, p.caption, p.dll) end print("--done") print(#procs1, #procs2)