Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><del>I think the COM+ Administrative components only lets you query the "static" configuration properties (e.g. Identity, IsEnabled) and doesn't let you query the dynamic properties of COM+ (e.g. PID).</p> <p>The only way I found to do what you want is using the COMSVCSLib (COM+ Services Type Library). </del> <p> <strong>UPDATE</strong>: Based on @Vagaus's comment, we can use <em>either</em> COM+ Administrative components or COM+ Services Type Library!</p> <p>With quite a bit of help from the article <a href="http://www.codeproject.com/KB/cs/comonitorproject.aspx" rel="noreferrer">Comonitor - A COM+ Monitor</a>. I've cobbled together some code that uses COM+ Services Type Library:</p> <pre><code>public static bool IsComPlusApplicationRunning(string appName) { int appDataSize = Marshal.SizeOf(typeof(COMSVCSLib.appData)); Type appDataType = typeof(COMSVCSLib.appData); uint appCount; IntPtr appDataPtr = IntPtr.Zero; GCHandle gh = GCHandle.Alloc(appDataPtr, GCHandleType.Pinned); IntPtr addressOfAppDataPtr = gh.AddrOfPinnedObject(); COMSVCSLib.IGetAppData getAppData = null; COMSVCSLib.TrackerServer tracker = null; try { tracker = new COMSVCSLib.TrackerServerClass(); getAppData = (COMSVCSLib.IGetAppData)tracker; getAppData.GetApps(out appCount, addressOfAppDataPtr); appDataPtr = new IntPtr(Marshal.ReadInt32(addressOfAppDataPtr)); for (int appIndex = 0; appIndex &lt; appCount; appIndex++) { COMSVCSLib.appData appData = (COMSVCSLib.appData)Marshal.PtrToStructure( new IntPtr(appDataPtr.ToInt32() + (appIndex * appDataSize)), appDataType); string currentAppName = GetPackageNameByPID(appData.m_dwAppProcessId); if (string.Compare(currentAppName, appName, StringComparison.OrdinalIgnoreCase) == 0) { Console.WriteLine("Application " + appName + " is running with PID " + appData.m_dwAppProcessId); return true; } } } finally { Marshal.FreeCoTaskMem(appDataPtr); if (tracker != null) { Marshal.ReleaseComObject(tracker); } gh.Free(); } return false; } private static string GetPackageNameByPID(uint PID) { COMSVCSLib.MtsGrp grpObj = new COMSVCSLib.MtsGrpClass(); try { object obj = null; COMSVCSLib.COMEvents eventObj = null; for (int i = 0; i &lt; grpObj.Count; i++) { try { grpObj.Item(i, out obj); eventObj = (COMSVCSLib.COMEvents)obj; if (eventObj.GetProcessID() == PID) { return eventObj.PackageName; } } finally { if (obj != null) { Marshal.ReleaseComObject(obj); } } } } finally { if (grpObj != null) { Marshal.ReleaseComObject(grpObj); } } return null; } </code></pre> <p><br /></p> <p>But we can also use the COM+ Administrative components (which seems simpler) to do the same thing:</p> <pre><code>public static bool IsComPlusApplicationRunning(string appName) { COMAdmin.COMAdminCatalog catalog = new COMAdmin.COMAdminCatalogClass(); COMAdmin.ICatalogCollection appCollection = (COMAdmin.ICatalogCollection)catalog.GetCollection("Applications"); appCollection.Populate(); Dictionary&lt;string, string&gt; apps = new Dictionary&lt;string, string&gt;(); COMAdmin.ICatalogObject catalogObject = null; // Get the names of the applications with their ID and store for later for (int i = 0; i &lt; appCollection.Count; i++) { catalogObject = (COMAdmin.ICatalogObject)appCollection.get_Item(i); apps.Add(catalogObject.get_Value("ID").ToString(), catalogObject.Name.ToString()); } appCollection = (COMAdmin.ICatalogCollection)catalog.GetCollection("ApplicationInstances"); appCollection.Populate(); for (int i = 0; i &lt; appCollection.Count; i++) { catalogObject = (COMAdmin.ICatalogObject)appCollection.get_Item(i); if (string.Compare(appName, apps[catalogObject.get_Value("Application").ToString()], StringComparison.OrdinalIgnoreCase) == 0) { Console.WriteLine(appName + " is running with PID: " + catalogObject.get_Value("ProcessID").ToString()); return true; } } return false; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload