How to enum modules in a 64bit process from a 32bit WOW process

后端 未结 3 1018
小蘑菇
小蘑菇 2020-12-05 14:53

I have a requirement to retrieve all modules of a 64bit process in a 32bit WOW process in Windows, EnumProcessModules would fail as described:

If this

3条回答
  •  悲哀的现实
    2020-12-05 15:25

    Use Windows Management Instrumentation (WMI). Example (Delphi):

    function GetProcessCount(const aFileName: string): Integer;
    var
      lValue: LongWord;
      lWMIService: OleVariant;
      lWMIItems: OleVariant;
      lWMIItem: OleVariant;
      lWMIEnum: IEnumVariant;
    begin
      Result := -1;
      lWMIService := GetWMIObject('winmgmts:\\.\root\CIMV2'); { Do not localize. }
      if (TVarData(lWMIService).VType = varDispatch) and (TVarData(lWMIService).VDispatch <> nil) then
      begin
        Result := 0;
        lWMIItems := lWMIService.ExecQuery(Format('SELECT * FROM Win32_Process WHERE Name=''%s''', [ExtractFileName(aFileName)])); { Do not localize. }
        lWMIEnum := IUnknown(lWMIItems._NewEnum) as IEnumVariant;
        while lWMIEnum.Next(1, lWMIItem, lValue) = 0 do
        begin
          Inc(Result);
        end;
      end;
    end;
    

提交回复
热议问题