Пример #1
0
        public static int GetRunningObjectCount()
        {
            int                     count = 0;
            UCOMIBindCtx            bc;
            UCOMIRunningObjectTable rot;
            UCOMIEnumMoniker        em;

            UCOMIMoniker[] moniker = new UCOMIMoniker[1];
            int            unused;

            ActiveX.CreateBindCtx(0, out bc);
            bc.GetRunningObjectTable(out rot);
            rot.EnumRunning(out em);
            while (0 == em.Next(1, moniker, out unused))
            {
                count++;
            }
            Marshal.ReleaseComObject(bc);
            Marshal.ReleaseComObject(rot);
            Marshal.ReleaseComObject(em);
            return(count);
        }
Пример #2
0
        // 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);
        }