// Gets the appropriate type of object info internal static ObjectInfo GetObjectInfo(bool comObject, Object obj) { ObjectInfo objInfo = ObjectInfo.GetObjectInfo(obj); if (objInfo != null) { return(objInfo); } if (TraceUtil.If(typeof(ObjectInfoFactory), TraceLevel.Verbose)) { TraceUtil.WriteLineVerbose(null, "getObjInfo: " + obj + " type: " + obj.GetType().FullName); } return(new ComObjectInfo(obj)); }
// Finds the COM running objects public static IList GetRunningObjects(ProgressDialog progress) { ArrayList runningObjects = new ArrayList(); Hashtable runningHash = new Hashtable(); UCOMIBindCtx bc; UCOMIRunningObjectTable rot; UCOMIEnumMoniker em; UCOMIMoniker[] monikers = new UCOMIMoniker[1]; ActiveX.CreateBindCtx(0, out bc); bc.GetRunningObjectTable(out rot); rot.EnumRunning(out em); // Look at each Moniker in the ROT int unused; while (0 == em.Next(1, monikers, out unused)) { try { UCOMIMoniker moniker = monikers[0]; Object obj; rot.GetObject(moniker, out obj); String monikerName; moniker.GetDisplayName(bc, null, out monikerName); ComObjectInfo comObjInfo; // Check for duplicates against the other running objects Object runObj = runningHash[obj]; if (runObj != null) { // Get the existing object's moniker comObjInfo = (ComObjectInfo) ObjectInfo.GetObjectInfo(obj); if (monikerName.Equals(comObjInfo._monikerName)) { TraceUtil.WriteLineInfo (typeof(ComObjectInfo), "ROT - Skipping duplicate: " + monikerName); progress.UpdateProgress(1); continue; } } else { runningHash.Add(obj, obj); } comObjInfo = (ComObjectInfo) ObjectInfoFactory.GetObjectInfo(true, obj); // Need moniker name before update progress comObjInfo.CalcRunningObjName(rot, bc, moniker, monikerName); progress.UpdateProgressText(comObjInfo.GetMonikerName()); progress.UpdateProgress(1); runningObjects.Add(comObjInfo); TraceUtil.WriteLineIf(typeof(ComObjectInfo), TraceLevel.Info, "ROT - added: " + comObjInfo.GetName() + " " + comObjInfo.ObjType + " " + Win32Utils.RegKeyToString (comObjInfo._classIdKey) + Win32Utils.RegKeyToString (comObjInfo._classNameKey)); } catch (Exception ex) { TraceUtil.WriteLineIf(typeof(ComObjectInfo), TraceLevel.Info, "ROT - Exception processing ROT entry: " + ex); progress.UpdateProgress(1); continue; } } Marshal.ReleaseComObject(em); Marshal.ReleaseComObject(bc); Marshal.ReleaseComObject(rot); return(runningObjects); }