The ProcessModuleCollection
instance returned by calling Process.Modules
has the information you need. Provided that both processes have the same bitness. So, if the target process is a 32 bit process, make sure your process is also a 32 bit process. And if the target process is a 64 bit process, then make sure your process is a 64 bit process.
From the output you include in the question it is clear that the scenario that produced that output is:
- A 64 bit OS.
- Your code executes in a 64 bit process.
- The target process is a 32 bit process.
The reason that you only enumerate those handful of modules is (presumably) that they are the 64 bit modules that are included in the 32 bit process running under the WOW64 emulator, together with the executable module.
You might be tempted to think that you can use the Windows API to enumerate modules in a process with a different bitness. But you cannot. Attempts to use CreateToolhelp32Snapshot
, Module32First
and Module32Next
yield the same results as your C# code that uses Process.Modules
. And that's not at all surprising really. It makes perfect sense that .net, which is implemented in Win32, would call the native Win32 API that is designed for this task.
Your solution is to make sure that the call to Process.Modules
is made from a 32 bit process. You will need to use some helper processes of different bitness if you need to be able to target both 32 and 64 bit processes.
Update
Ben Voigt point me to EnumerateLoadedModules64 from the Debug Help API. I confess to being unaware of this. However, it does appear to have the same bitness limitations as the tool help API.
Finally, there is also EnumProcessModulesEx which can enumerate 32 bit modules from a 64 bit process. If you pass LIST_MODULES_32BIT
then you can indeed extract the 32 bit modules loaded into an external 32 bit process, from a calling process that is 64 bit.