I\'m trying to list dll(s) loaded to processe with the following code:
Process[] ObjModulesList = Process.GetProcessesByName(\"iexplore\");
foreach (Process
You have to compile you app with x64 target.
Otherwise you can consult: http://www.codeproject.com/Articles/301/Display-Loaded-Modules-v
You can use WMI, here is a piece of code that gets all processes and relative modules:
var wmiQueryString = string.Format("select * from CIM_ProcessExecutable");
Dictionary<int, ProcInfo> procsMods = new Dictionary<int, ProcInfo>();
using (var searcher = new ManagementObjectSearcher(string.Format(wmiQueryString)))
using (var results = searcher.Get())
{
foreach (var item in resMg.Cast<ManagementObject>())
{
try
{
var antecedent = new ManagementObject((string)item["Antecedent"]);
var dependent = new ManagementObject((string)item["Dependent"]);
int procHandleInt = Convert.ToInt32(dependent["Handle"]);
ProcInfo pI = new ProcInfo { Handle = procHandleInt, FileProc = new FileInfo((string)dependent["Name"]) };
if (!procsMods.ContainsKey(procHandleInt))
{
procsMods.Add(procHandleInt, pI);
}
procsMods[procHandleInt].Modules.Add(new ModInfo { FileMod = new FileInfo((string)antecedent["Name"]) });
}
catch (System.Management.ManagementException ex)
{
// Process does not exist anymore
}
}
}
In procsMods
we have stored processes and modules, now we print them:
foreach (var item in procsMods)
{
Console.WriteLine(string.Format("{0} ({1}):", item.Value.FileProc.Name, item.Key));
foreach (var mod in item.Value.Modules)
{
Console.WriteLine("\t{0}", mod.FileMod.Name);
}
}
And these are ProcInfo
and ModInfo
classes:
class ProcInfo
{
public FileInfo FileProc { get; set; }
public int Handle { get; set; }
public List<ModInfo> Modules { get; set; }
public ProcInfo()
{
Modules = new List<ModInfo>();
}
}
class ModInfo
{
public FileInfo FileMod { get; set; }
}