Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Which process has a DLL open?


This question is answered.


Permlink Replies: 2 - Last Post: Dec 12, 2017 4:16 AM Last Post By: Arthur Hoornweg Threads: [ Previous | Next ]
Arthur Hoornweg

Posts: 395
Registered: 6/2/98
Which process has a DLL open?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2017 12:05 AM
Hello all,

does anyone know how to find out (in source code) which processes have a certain DLL loaded? This is going to be part of a setup routine.

I'm looking for a solution that works reliably on ancient (pre-Vista) Windows versions too....

Kind regards!
Arthur

Remy Lebeau (Te...


Posts: 9,079
Registered: 12/23/01
Re: Which process has a DLL open?
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Oct 16, 2017 12:13 PM   in response to: Arthur Hoornweg in response to: Arthur Hoornweg
Arthur Hoornweg wrote:

does anyone know how to find out (in source code) which processes
have a certain DLL loaded? This is going to be part of a setup
routine.

Yes, but it is not trivial to do. You have to examine every module
loaded in every running process, looking for the filename you are
interested in.

Look at EnumProcesses(), OpenProcess(), and EnumProcessModules/Ex():

Enumerating All Processes
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682623.aspx

Enumerating All Modules For a Process
https://msdn.microsoft.com/en-us/library/windows/desktop/ms682621.aspx

or at CreateToolhelp32Snapshot() and Module32(First|Next)():

Process Walking
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684887.aspx

Module Walking
https://msdn.microsoft.com/en-us/library/windows/desktop/ms684236.aspx

--
Remy Lebeau (TeamB)
Arthur Hoornweg

Posts: 395
Registered: 6/2/98
Re: Which process has a DLL open?  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Dec 12, 2017 4:16 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

Yes, but it is not trivial to do. You have to examine every module
loaded in every running process, looking for the filename you are
interested in.

Look at EnumProcesses(), OpenProcess(), and EnumProcessModules/Ex():

Thank you! I have finally succeeded in getting this to work for 32-bit processes.

The one thing I can't seem to get working is when a 32-bit process wants to know about which 64-bit process has a DLL open. Somehow only 64 bit processes can do this. Which is a bit of a p.i.t.a. because the system I use for creating setups (Inno Setup) happens to be a 32-bit process. The only thing that might work is to include and spawn a 64-bit helper process.
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02