12

I want to list all the dlls loaded by a process, like this:

enter image description here

How could I get the information with Python on Windows?

Community
  • 1
  • 1
wong2
  • 34,358
  • 48
  • 134
  • 179
  • I keep trying to figure out how to do it with pywin32 but the documentation is nearly nonexistent and I'm not familiar enough with COM to know exactly where to start anyway. But I have a sneaking suspicion that COM via pywin32 will be able to get this info. – Daniel DiPaolo Apr 05 '11 at 15:42
  • @Daniel, its `win32process.EnumProcessModules()` etc. (normal Windows API, no COM). See answer below. – kxr Mar 23 '22 at 12:50

3 Answers3

17

Using the package psutil it is possible to get a portable solution! :-)

# e.g. finding the shared libs (dll/so) our python process loaded so far ...
import psutil, os
p = psutil.Process( os.getpid() )
for dll in p.memory_maps():
  print(dll.path)
Community
  • 1
  • 1
Zappotek
  • 344
  • 2
  • 5
  • rss: aka “Resident Set Size”, this is the non-swapped physical memory a process has Rss: 又名“驻留集大小”,这是进程拥有的非交换物理内存 – CS QGB Jul 24 '22 at 09:49
9

Using listdlls:

import os
os.system('listdlls PID_OR_PROCESS_NAME_HERE')
Fábio Diniz
  • 10,077
  • 3
  • 38
  • 45
1

With pywin32 already installed do like:

import win32api, win32process
for h in win32process.EnumProcessModules(win32process.GetCurrentProcess()):
    print(win32api.GetModuleFileName(h)

Use functions like win32api.GetFileVersionInfo(), .EnumResourceNames() ... on the dll paths to get dll attribute data.

kxr
  • 4,841
  • 1
  • 49
  • 32