How to enum 32bit process's modules from a 64b

2019-08-17 11:14发布

问题:

I have the code:

        foreach (var process in Process.GetProcesses()) {
            if (process.ProcessName.ToLowerInvariant().StartsWith("iexplore")) {

                foreach (ProcessModule module in process.Modules) {
                    string descr = module.FileVersionInfo.FileDescription;
                    MessageBox.Show(module.FileName);
                }
            }
        }

My app is set on "Any CPU" configuration, so it should run as 64bit process on my Win7 x64. I tried to enumerate iexplore.exe's modules (the 32bit version). My question is how to enum the modules of 32bit apps from 64bit app? It returns only the WoW dlls.

回答1:

I have the same problem in my application, although I think you got it backwards (see may comment to your question).

Actually, it is not possible to enumerate the modules of 32bit process on 64bit Windows, if your own process is a 64bit process.

You'll only see the following modules (which are the only 64bit modules in the 32 bit process):

  • The main module (i.e. the executable)
  • NtDll.dll
  • Wow64.dll
  • Wow64cpu.dll
  • Wow64win.dll

Which is most likely due to the fact that Process.Modules uses the EnumProcessModules Win32 API internally, which has limitations when working with 32/64 bit. MSDN suggests (for native applications) to use EnumProcessModulesEx, which you could P/Invoke as well.

It looks like others have discovered this issue as well.