Click here to Skip to main content
13,358,079 members (56,592 online)
Click here to Skip to main content
Add your own
alternative version


20 bookmarked
Posted 28 Jul 2005

COM+ Running Process

, 28 Jul 2005
Rate this:
Please Sign up or sign in to vote.
Monitoring COM+ running applications.

Running COM+ Process (Application snapshot)


Following is an application for those who want to know, what is the COM+ application name behind a specific process ID (i.e. dllhost.exe process) and for those who want to monitor memory used by these COM+ components.


There are two ways that COM+ can host .NET components: Library applications and Server applications. A library application runs the component in the caller process while a server application runs the component in a dedicate process that COM+ creates, called Dllhost.exe. Server application runs in a separate process affecting the overall performance of the application that needs to cross the process boundary to call component services.

Many organizations and individuals want to monitor their COM+ applications, like what is the COM+ application name behind a process ID and how much memory is being used by a COM+ component. This inspired me to make a simple application that possess the above features mentioned.

Using the code

The first step is to add reference to the following namespaces:

using System;
using System.Drawing;
using System.Diagnostics;
using System.ComponentModel;
using System.Windows.Forms;
using COMSVCSLib; // Path = C:\Windows\System32\comsvcs.dll
using System.Runtime.InteropServices;

Whenever you press "Get Application(s)" button, inside the btnGetApplications_Click(object sender, System.EventArgs e) function, the GetCOMPlusApplicationsList(); function is called. This is the main function that gets the list of all running COM+ applications and also gets the associated process ID.

/// This function retrieves all the running COM+ commponent services 
/// and also retrieves their application ID.
public  GetCOMPlusApplicationsList()
    // MtsGrp interface provides methods
    // for enumeration through running packages.
    COMSVCSLib.MtsGrp GrpObj = null;
    Type dcomType = Type.GetTypeFromProgID("mts.MtsGrp");
    // Creating new instance of MtsGrp component.
    Object dcomObj = Activator.CreateInstance( dcomType );

    GrpObj = (COMSVCSLib.MtsGrp) dcomObj;
    object obj = null;
    COMSVCSLib.COMEvents eventObj = null;
    for (int i = 0 ;i < GrpObj.Count ; ++i)
        GrpObj.Item (i, out obj);
        eventObj = (COMSVCSLib.COMEvents) obj;
        // Add information to list view.
        // Release the resources held by object.
        obj = null;
        eventObj = null;
    Marshal.ReleaseComObject( dcomObj ); 
    dcomObj = null;

In GetCOMPlusApplicationsList() function, first of all, it creates a reference object of interface COMSVCSLib.MtsGrp which is used to enumerate through the running packages. Later you need to get the type associated with the specified program identifier (progID). In this case, "mts.MtsGrp" progID is specified to get the type associated with this component. The next step is to create an instance of this type object by calling the .NET class function Activator.CreateInstance( dcomType ).

Now you get the MtsGrp object. You can get each instance by using the GrpObj.Item (i, out obj) function, and type cast it to COMEvents object like this:

eventObj = (COMSVCSLib.COMEvents) obj;

Next step is calling the function eventObj.GetProcessID() and eventObj.PackageName function and properties respectively to get the process ID and application name of the running COM+ application. After that AddtoListView function is called which adds the process ID and application name to the ListView. After that you need to call the Marshal.ReleaseComObject(obj) function defined in the System.Runtime.InteropServices.Marshal to release the memory resources held by this object. See what is happening in AddtoListView function:

private void AddtoListView(int pid, string appName)
    listItem = this.comlistView.Items.Add(pid.ToString());

When you get the COM+ applications, then you can get the memory used by these COM+ applications. For this, you can select the COM+ application you want to know about and after that press "Get Memory" button which in response shows you the memory usage in terms of bytes. Now let's see what happens in the Click event of the "Get Memory" button.

private void getMemoryButton_Click(object sender, System.EventArgs e)
    // Getting process id from pid text box.
    string pid = this.pidTextBox.Text ;
    if(pid =="")
        MessageBox.Show("Please enter a process Id!", "Process ID");

    // Get all the process of the system.
    Process []getProcess = Process.GetProcesses();

    // Iterate through these process to find the specific process.
    foreach(Process pro in getProcess)
        if(pro.Id.ToString() == pid)
            // getting physical memory used by this process.
            this.phyMemTextBox.Text = pro.WorkingSet.ToString() + " bytes"; 

            // getting virtual memory used by this process.
            this.virTextBox.Text = pro.VirtualMemorySize.ToString() + " bytes";

    MessageBox.Show("Invalid process Id","Invalid ID");

Points of Interest

This was the first assignment given to me in my software house Ultimus. First I tried hard to get the running COM+ packages, but later when I explored a lot, this solution stuck into my mind and I finally came with this idea. Before that I never got familiar with COM+ components. But this application could be very useful for those organizations which usually use COM+ packages.


  • 28 July 2005: Initial release.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
Pakistan Pakistan
Muhammad Rizwan is a Software engineer. He did his M.Sc. in Computer Science from Quaid-i-Azam university Islamabad, Pakistan.
He has almost One year experience working in .NET technologies. He feels free to work in Visual C#.NET, Visual C++ and in Java as well. You can reach him at


You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
kevin.dmonte15-Apr-11 22:12
memberkevin.dmonte15-Apr-11 22:12 
GeneralCOm and COM+ Pin
saurabh.surana31-Mar-10 0:14
membersaurabh.surana31-Mar-10 0:14 
GeneralWorks fine Pin
aalday14-Oct-06 3:31
memberaalday14-Oct-06 3:31 
GeneralError Pin
Sachs14-Feb-06 9:54
memberSachs14-Feb-06 9:54 
GeneralRe: Error Pin
M_Rizwan14-Feb-06 19:20
memberM_Rizwan14-Feb-06 19:20 
GeneralRe: Error Pin
simpleperson28-Feb-06 9:03
membersimpleperson28-Feb-06 9:03 
GeneralRe: Error Pin
M_Rizwan1-Mar-06 18:40
memberM_Rizwan1-Mar-06 18:40 
GeneralRe: Error Pin
simpleperson4-Mar-06 4:33
membersimpleperson4-Mar-06 4:33 
GeneralRe: Error Pin
Andrzej Hamkalo7-Jul-06 3:25
memberAndrzej Hamkalo7-Jul-06 3:25 
GeneralCongrates Pin
Babarsaeed3-Aug-05 20:49
memberBabarsaeed3-Aug-05 20:49 

have red your article , and i find it best nd nice,

keep the moral high..

wish u all da best!

Allah hafiz

GeneralCongrates Pin
Babarsaeed3-Aug-05 20:40
memberBabarsaeed3-Aug-05 20:40 
GeneralNice work u did Riz Pin
yasirqau31-Jul-05 21:54
memberyasirqau31-Jul-05 21:54 
QuestionLinks? Pin
fwsouthern28-Jul-05 6:44
memberfwsouthern28-Jul-05 6:44 
AnswerRe: Links? Pin
M_Rizwan29-Jul-05 4:14
memberM_Rizwan29-Jul-05 4:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 28 Jul 2005
Article Copyright 2005 by M_Rizwan
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid