进程模块信息
来源:互联网 发布:诸暨法院淘宝网拍卖网 编辑:程序博客网 时间:2024/06/05 16:29
uses Tlhelp32;var modList: TStrings;procedure ModuleEnum(processid: Dword;Var ProcList: TstringList);var ModuleList: Thandle; pm: TMODULEENTRY32; isFind:Boolean;begin ModuleList := CreateToolhelp32Snapshot (TH32CS_SNAPMODULE, processID); pm.dwSize := sizeof(TMODULEENTRY32); isFind:=module32first(ModuleList, pm); while isFind do begin ProcList.Add(pm.szexepath); isFind:=module32next(ModuleList, pm) end; closehandle(ModuleList);end;procedure TForm1.cbb1Click(Sender: TObject);var ID, ProcID: DWORD; i: Integer; lt: TStrings; itm: TListItem;begin lv1.Clear; try Lt := TStringList.Create; Lt.Clear; ID := cbb1.ItemIndex; ProcID := StrToInt(modList.Strings[id]); ModuleEnum(ProcID,Lt); for i := 0 to Lt.Count - 1 do begin itm := lv1.Items.Add; itm.Caption := lt.Strings[i]; end; finally lt.Free; end;end;procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);begin modList.Free;end;procedure TForm1.FormCreate(Sender: TObject);var Thand32: THandle; procstruct: TProcessEntry32; Pname: string; pid: DWORD; finded: boolean;begin try Thand32 := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); procstruct.dwSize := SizeOf(procstruct); finded := Process32First(Thand32, procstruct); modList := TStringList.Create; modList.Clear; while finded do begin pname := procstruct.szExeFile; cbb1.Items.Add(pname); Pid := procstruct.th32ProcessID; modList.Add(IntToStr(Pid)); finded := Process32Next(Thand32, procstruct); end; cbb1.ItemIndex := 0; finally CloseHandle(Thand32); end;