예제 #1
0
        static void Main(string[] args)
        {
            IRunningObjectTable Rot = null;

            GetRunningObjectTable(0, out Rot);//pobranie obiektu Rot
            //Co my dostajemy w obiekcie pod nazwa ROT? => nadzieje na lepsze jutro

            /*
             * HRESULT GetRunningObjectTable(
             *    DWORD                reserved,
             *    LPRUNNINGOBJECTTABLE *pprot
             *  );
             *
             *  reserved
             *
             *  This parameter is reserved and must be 0.
             *
             *  pprot
             *
             *  The address of an IRunningObjectTable* pointer variable that receives the interface pointer to the local ROT.
             *  When the function is successful, the caller is responsible for calling Release on the interface pointer.
             *  If an error occurs, *pprot is undefined.
             */

            if (Rot == null)
            {
                return;
            }
            IEnumMoniker monikerEnumerator = null;//inform. moniker (obiekt pełniący rolę identyfikatora)

            //Enumerates the components of a moniker or the monikers in a table of monikers.
            Rot.EnumRunning(out monikerEnumerator);//pobranie obiektu IEnumMoniker => dowiedzisc sie wiecej o nim....
            if (monikerEnumerator == null)
            {
                return;
            }
            monikerEnumerator.Reset();// Resets the enumeration sequence to the beginning

            List <object> instances = new List <object>();

            IntPtr pNumFetched = new IntPtr();//Handle - Typ specyficzny dla platformy, który jest używany do reprezentowania wskaźnika lub uchwytu.

            IMoniker[] monikers = new IMoniker[1];
            while (monikerEnumerator.Next(1, monikers, pNumFetched) == 0)//Retrieves the specified number of items in the enumeration sequence.
            {
                /*
                 * HRESULT Next(
                 *  ULONG    celt,
                 *  IMoniker **rgelt,
                 *  ULONG    *pceltFetched
                 * );
                 * celt -> The number of items to be retrieved.
                 * rgelt -> An array of enumerated items.
                 * pceltFetched -> This parameter can be NULL if celt is 1
                 *
                 */
                IBindCtx bindCtx;              //Provides access to a bind context, which is an object that stores information about a particular moniker binding operation.
                CreateBindCtx(0, out bindCtx); //po co?
                if (bindCtx == null)
                {
                    continue;       // sprawdzenie warunkow pocztakowy nastepnej funkcji
                }
                string displayName; //clsid
                monikers[0].GetDisplayName(bindCtx, null, out displayName);
                //Console.WriteLine(displayName + "@#$" + pNumFetched);

                /*
                 * HRESULT GetDisplayName(
                 *    IBindCtx *pbc,
                 *    IMoniker *pmkToLeft,
                 *    LPOLESTR *ppszDisplayName
                 *  );
                 *  Parameters
                 *  pbc
                 *
                 *  A pointer to the IBindCtx interface on the bind context to be used in this operation. The bind context caches objects bound during the binding process, contains parameters that apply to all operations using the bind context, and provides the means by which the moniker implementation should retrieve information about its environment.
                 *
                 *  pmkToLeft
                 *
                 *  If the moniker is part of a composite moniker, pointer to the moniker to the left of this moniker. This parameter is used primarily by moniker implementers to enable cooperation between the various components of a composite moniker. Moniker clients should pass NULL.
                 *
                 *  ppszDisplayName
                 *
                 *  The address of a pointer variable that receives a pointer to the display name string for the moniker. The implementation must use IMalloc::Alloc to allocate the string returned in ppszDisplayName, and the caller is responsible for calling IMalloc::Free to free it. Both the caller and the implementation of this method use the COM task allocator returned by CoGetMalloc. If an error occurs, the implementation must set *ppszDisplayName should be set to NULL.
                 */
                //object ComObject;
                //SYSTEMTIME stUTC;
                System.Runtime.InteropServices.ComTypes.FILETIME a = new System.Runtime.InteropServices.ComTypes.FILETIME();
                Rot.GetTimeOfLastChange(monikers[0], out a);
                //Rot.GetObject(monikers[0], out ComObject);
                //if (ComObject == null) continue;
                //instances.Add(ComObject);
                // break;//nie wiem czy po mojej przrerubce bedzie spelnial to samo zadanie
            }



            test();
        }
예제 #2
0
        public static List<RunningObjectTableComponentInfo> GetComponentsFromROT()
        {
            IEnumMoniker monikerList = null;
            IRunningObjectTable runningObjectTable = null;
            List<RunningObjectTableComponentInfo> resultList = new List<RunningObjectTableComponentInfo>();
            try
            {
                // query table and returns null if no objects runnings
                if (GetRunningObjectTable(0, out runningObjectTable) != 0 || runningObjectTable == null)
                    return null;

                // query moniker & reset
                runningObjectTable.EnumRunning(out monikerList);
                monikerList.Reset();

                IMoniker[] monikerContainer = new IMoniker[1];
                IntPtr pointerFetchedMonikers = IntPtr.Zero;

                // fetch all moniker
                while (monikerList.Next(1, monikerContainer, pointerFetchedMonikers) == 0)
                {
                    // create binding object
                    IBindCtx bindInfo;
                    CreateBindCtx(0, out bindInfo);

                    // query com proxy info      
                    object comInstance = null;
                    runningObjectTable.GetObject(monikerContainer[0], out comInstance);

                    string ppszDisplayName;
                    try { monikerContainer[0].GetDisplayName(bindInfo, null, out ppszDisplayName); }
                    catch { ppszDisplayName = ""; }

                    Guid pClassID;
                    try { monikerContainer[0].GetClassID(out pClassID); }
                    catch { pClassID = Guid.Empty; }
                    
                    System.Runtime.InteropServices.ComTypes.FILETIME pLastChangedFileTime;
                    try { runningObjectTable.GetTimeOfLastChange(monikerContainer[0], out pLastChangedFileTime);}
                    catch { pLastChangedFileTime = new System.Runtime.InteropServices.ComTypes.FILETIME(); }
                    
                    long pcbSize;
                    try { monikerContainer[0].GetSizeMax(out pcbSize);}
                    catch { pcbSize = 0;}
                    
                    
                    Boolean IsDirty;
                    try {IsDirty = (monikerContainer[0].IsDirty() == 0); }
                    catch {IsDirty = false;}

                    Boolean IsRunning;
                    try {IsRunning = (runningObjectTable.IsRunning(monikerContainer[0]) == 0); }
                    catch {IsRunning = false;}

                    // creating the unbound object to hold the Data out of the current component IMoniker
                    RunningObjectTableComponentInfo ROTComponent = new RunningObjectTableComponentInfo(
                        ppszDisplayName,
                        pClassID,
                        ConvertFromFILETIME(pLastChangedFileTime),
                        pcbSize,
                        TypeDescriptor.GetComponentName(comInstance, false),
                        TypeDescriptor.GetClassName(comInstance),
                        IsRunning,
                        IsDirty
                    );

                    resultList.Add(ROTComponent);

                    // clean up and release object 
                    Marshal.ReleaseComObject(comInstance);
                    Marshal.ReleaseComObject(bindInfo);
                }

                // not running
                return resultList;
            }
            finally
            {
                // release proxies
                if (runningObjectTable != null)
                    Marshal.ReleaseComObject(runningObjectTable);
                if (monikerList != null)
                    Marshal.ReleaseComObject(monikerList);
            }
        }