11

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
  • 31,730
  • 45
  • 128
  • 170
  • 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

15

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
  • 325
  • 2
  • 4
8

Using listdlls:

import os
os.system('listdlls PID_OR_PROCESS_NAME_HERE')
Fábio Diniz
  • 9,719
  • 3
  • 36
  • 45
0

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
  • 3,892
  • 41
  • 27