get AppDomains collection from a process.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akshaycjoshi
    New Member
    • Jan 2007
    • 153

    get AppDomains collection from a process.

    I was wondering how to get a collection of all the AddDomains in the process.
    Like Process.GetCurr entProcess().Ge tAppDomains();

    Any clues to get that ?

    All i wanna do is enumerate all the appdomains in a specific process.
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Originally posted by akshaycjoshi
    I was wondering how to get a collection of all the AddDomains in the process.
    Like Process.GetCurr entProcess().Ge tAppDomains();

    Any clues to get that ?

    All i wanna do is enumerate all the appdomains in a specific process.
    Have a look at this
    Thomas Scheidegger
    Jamie Cansdale

    For the below code to work add reference to WINDOWS\Microso ft.NET\Framewor k\v2.0.50727\ms coree.tlb

    Code:
    public void GetApp()
            {
                AppDomain one =  AppDomain.CreateDomain("One");
                AppDomain two =  AppDomain.CreateDomain("Two");
    
                CorRuntimeHostClass host = new CorRuntimeHostClass();
    
                try
                {
    
                    ArrayList list = new ArrayList();
                    IntPtr enumHandle;
    
                    host.EnumDomains(out enumHandle);
    
                    while (true)
                    {
    
                        object domain;
    
                        host.NextDomain(enumHandle, out domain);
    
                        if (domain == null) break;
    
                        list.Add((AppDomain)domain);
    
                    }
    
                    host.CloseEnum(enumHandle);
    
                    foreach (object o in list)
                    {
                        AppDomain aa = o as AppDomain;
                        Console.WriteLine(aa.FriendlyName);
                    }
                  
                }
    
                finally
                {
    
                    Marshal.ReleaseComObject(host);
                    //AppDomain aa in                
    
                }
            
            }//
    i hope theres a easier way of doin this... maybe you should look into WMI classes... I havent found a simple way of doin it ...like u said ..Process.GetCu rrentProcess(). GetAppDomains() ...
    i may have completely missed something simpler....
    hope this helps.. let me know if you find a simpler way ...

    Comment

    Working...