wong2
wong2

Reputation: 35750

How to list all dlls loaded by a process with Python?

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?

Upvotes: 14

Views: 10566

Answers (3)

kxr
kxr

Reputation: 5538

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.

Upvotes: 2

Zappotek
Zappotek

Reputation: 384

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)

Upvotes: 20

Fábio Diniz
Fábio Diniz

Reputation: 10363

Using listdlls:

import os
os.system('listdlls PID_OR_PROCESS_NAME_HERE')

Upvotes: 9

Related Questions