Get All DLLS For A Process

筅森魡賤 提交于 2020-01-13 09:25:10

问题


I would like to get a list of all the dlls loaded for a given Process. I am currently using .NET Framework 4.0. I am aware that there is a bug when trying to access all managed dlls through the Process.Modules property. (Only lists the unmanaged dlls). I need a way to programmatically retrieve all of these dlls.

 Process[] myProcess = Process.GetProcessesByName("MyProcess");
 if(myProcess.Count() > 0) 
 {
      foreach (ProcessModule processModule in myProcess[0].Modules)
      //get information
 }

EDIT: The process I am interested in is not in the current AppDomain.


回答1:


I am aware that there is a bug

No, that's not a bug. It was an intentional design change in CLR v4, Microsoft did not keep that a secret. Previous versions of the CLR made an effort to emulate loaded assemblies as though they were unmanaged DLLs. But that just stopped making sense when they implemented the side-by-side in-process CLR versioning feature. It's gone and won't come back.

This isn't exactly a major problem, getting the list of loaded assemblies in another process is well supported by the debugging interface. ICorDebugAppDomain::EnumerateAssemblies() is the ticket. Well, not exactly as easy to use as Process.Modules. Use the MDbg sample to find out how to use it.



来源:https://stackoverflow.com/questions/14863369/get-all-dlls-for-a-process

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!