日期:2014-05-20  浏览次数:20800 次

有谁知道如何列举一个进程的所有的应用程序域?
查了半天的文档,发现只能得到当前的应用程序域,而不能得到一个进程所有的应用程序域。
痛苦,求解救。

------解决方案--------------------
Add the following as a COM reference - ~\WINDOWS\Microsoft.NET\Framework\v2.0.50727\mscor ee.tlb



using mscoree;
 using System.Runtime.InteropServices;
 
 public void GetAllAppDomains()
         {
 
             AppDomain one = AppDomain.CreateDomain("One");
             AppDomain two = AppDomain.CreateDomain("Two"); 
            // Creates 2 app domains           
 
             List<AppDomain> appDomains = new List<AppDomain>();
 
             IntPtr enumHandle = IntPtr.Zero;
 
             CorRuntimeHostClass host = new CorRuntimeHostClass();          
 
             try
             {
 
                 host.EnumDomains(out enumHandle);
 
                 object domain = null;
 
                 AppDomain tempDomain;
 
                 while (true)
                 {
 
                     host.NextDomain(enumHandle, out domain);
 
                     if (domain == null)
                     {
                         break;
                     }
 
                     tempDomain = domain as AppDomain;
 
                     appDomains.Add(tempDomain);
 
                 }               
 
             }
 
             catch (Exception ex)
             {
                 Console.WriteLine(ex.ToString());          
             }
 
             finally
             {
                 host.CloseEnum(enumHandle);
                 int rel= Marshal.ReleaseComObject(host);
             }
 
             Assembly[] assemblies;
             foreach (AppDomain app in appDomains)
             {
                 Console.WriteLine(app.FriendlyName);
 
                 assemblies = app.GetAssemblies();