2

I'm seeking for a way to get DLL names from a running process, sorry if I'm poorly expressing myself though.

I need to "connect" to this process via it's name or PID and retrieve the DLL names that it's using if that's possible.

Regards.

user1943911
  • 35
  • 1
  • 3
  • 1
    Yes, that is possible... please show some source code... what have you tried ? what exactly is not working ? – Yahia Jan 09 '13 at 17:49
  • Certainly possible with PInvoke, the win32 API is EnumProcessModules(Ex). No idea if possible in stock .NET without PInvoke or third party wrappers. – Zarat Jan 09 '13 at 17:52

1 Answers1

6

Yes it is possible. You can use the Process class. It has a Modules property that lists all the loaded modules.

For example, to list all processes and all modules to the console:

Process[] processes = Process.GetProcesses();

foreach(Process process in processes) {
    Console.WriteLine("PID:  " + process.Id);
    Console.WriteLine("Name: " + process.ProcessName);
    Console.WriteLine("Modules: ");

    foreach(ProcessModule module in process.Modules) {
        Console.WriteLine(module.FileName);
    }
}

You can of course check Process.Id for the PID you would like etc.

For more information check out the documentation for this class:-

http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx

Note: This code might get upset for certain system processes which you will not have access permission to.

Deniz
  • 429
  • 1
  • 4
  • 19
Lloyd
  • 29,197
  • 4
  • 84
  • 98
  • 2
    This code will also get upset if the process executing it is 32bit and 64bit modules are being accessed. `"A 32 bit processes cannot access modules of a 64 bit process.` – StoriKnow Jan 09 '13 at 19:34
  • @Sam Yeh. I guess you could write some kind of stub you can dump and execute that returns you the list, hackish though :/ – Lloyd Jan 10 '13 at 09:43
  • The second foreach loop is what did the trick for me! So simple, yet it still eluded me. Thanks for sharing, Lloyd! You saved me a bunch of headaches :) – kayleeFrye_onDeck Jan 05 '15 at 22:59