コード例 #1
0
        /// <summary>
        /// Removes an object previously registered with RegisterObject(,).
        /// </summary>
        /// <param name="register">The registration id (regid) returned from RegisterObject().</param>
        /// <returns></returns>
        public int RevokeActiveObject(int register)
        {
            int hr;

            hr = RotNativeMethods.RevokeActiveObject(register, IntPtr.Zero);
            return(hr);
        }
コード例 #2
0
        /// <summary>
        /// This allows us to register an object in the Running Object Table
        /// </summary>
        /// <param name="obj">A Com interface pointer owned by the object</param>
        /// <param name="stringId">A display name for the object</param>
        /// <returns>Returns two integers as an array, the first is the HRESULT of system calls and if successful the second is the registration id (regid).  You'll need the regid to revoke from the ROT when tidying up.</returns>
        public int[] RegisterObject(object obj, string stringId)
        {
            int[] retval = new int[] { 0, 0 };
            int   regId  = -1;

            System.Runtime.InteropServices.ComTypes.IRunningObjectTable pROT     = null;
            System.Runtime.InteropServices.ComTypes.IMoniker            pMoniker = null;
            int hr;

            if ((hr = RotNativeMethods.GetRunningObjectTable((int)0, out pROT)) != 0)
            {
                retval[0] = hr;
                return(retval);    //(hr);
            }
            // File Moniker has to be used because in VBS GetObject only works with file monikers in the ROT
            if ((hr = RotNativeMethods.CreateFileMoniker(stringId, out pMoniker)) != 0)
            {
                retval[0] = hr;
                return(retval);    //(hr);
            }
            int ROTFLAGS_REGISTRATIONKEEPSALIVE = 1;

            regId     = pROT.Register(ROTFLAGS_REGISTRATIONKEEPSALIVE, obj, pMoniker);
            retval[0] = 0;
            retval[1] = regId;
            return(retval);
        }
コード例 #3
0
        /// <summary>
        /// For VBA Clients we can use COM interop compatible types to return table as string array.
        /// </summary>
        /// <returns>An string array of all the entries in the Running Object Table.</returns>
        public string[] TableAsStringArray()
        {
            List <string>       itemsList = new List <string>();
            IBindCtx            ctx;
            IRunningObjectTable table;
            IEnumMoniker        mon;

            IMoniker[] lst = new IMoniker[1];
            RotNativeMethods.CreateBindCtx(0, out ctx);
            ctx.GetRunningObjectTable(out table);
            table.EnumRunning(out mon);
            while (mon.Next(1, lst, IntPtr.Zero) == 0)
            {
                string displayName;
                lst[0].GetDisplayName(ctx, lst[0], out displayName);
                itemsList.Add(displayName);
            }
            return(itemsList.ToArray());
        }
コード例 #4
0
        /// <summary>
        /// This is the equivalent of VBA's GetObject where one supplies a filename or other moniker to retrieve an interface pointer to object.
        /// </summary>
        /// <param name="sRotEntry"></param>
        /// <returns>A COM interface pointer to object in running object table specified by entry.</returns>
        public object GetObject(string sRotEntry)
        {
            Object              retVal = null;
            IBindCtx            ctx;
            IRunningObjectTable table;
            IEnumMoniker        mon;

            IMoniker[] lst = new IMoniker[1];
            RotNativeMethods.CreateBindCtx(0, out ctx);
            ctx.GetRunningObjectTable(out table);
            table.EnumRunning(out mon);
            while (mon.Next(1, lst, IntPtr.Zero) == 0)
            {
                string displayName;
                lst[0].GetDisplayName(ctx, lst[0], out displayName);
                if (displayName == sRotEntry)
                {
                    table.GetObject(lst[0], out retVal);
                }
            }
            return(retVal);
        }
コード例 #5
0
        public RotTableEntry[] DetailedTableAsArray()
        {
            List <RotTableEntry> itemsList = new List <RotTableEntry>();
            IBindCtx             ctx;
            IRunningObjectTable  table;
            IEnumMoniker         mon;

            IMoniker[] lst = new IMoniker[1];
            RotNativeMethods.CreateBindCtx(0, out ctx);
            ctx.GetRunningObjectTable(out table);
            table.EnumRunning(out mon);
            while (mon.Next(1, lst, IntPtr.Zero) == 0)
            {
                RotTableEntry item = new RotTableEntry();
                item.monikerDetails = new MonikerDetails();
                {
                    Guid guid;
                    lst[0].GetClassID(out guid);
                    item.monikerDetails.monikerClassId = RotNativeMethods.StringFromCLSID(guid);
                    switch (item.monikerDetails.monikerClassId)
                    {
                    case "{00000303-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "FileMoniker";
                        break;

                    case "{00000304-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "ItemMoniker";
                        break;

                    case "{00000305-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "AntiMoniker";
                        break;

                    case "{00000306-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "PointerMoniker";
                        break;

                    case "{00000308-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "PackageMoniker";
                        break;

                    case "{00000309-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "CompositeMoniker";
                        break;

                    case "{0000031A-0000-0000-C000-000000000046}":
                        item.monikerDetails.monikerType = "ClassMoniker";
                        break;

                    default:
                    {
                        RegistryKey monikerClassKey = Registry.ClassesRoot.OpenSubKey("CLSID\\" + item.monikerDetails.monikerClassId);
                        if (monikerClassKey == null)
                        {
                            item.monikerDetails.monikerType = "Failed to identify moniker";
                        }
                        else
                        {
                            item.monikerDetails.monikerType = monikerClassKey.GetValue(null).ToString();
                        }
                    }
                    break;
                    }
                }
                {
                    string displayName;
                    lst[0].GetDisplayName(ctx, lst[0], out displayName);
                    item.displayName = displayName;
                    item.className   = "";
                }
                {
                    if (item.monikerDetails.monikerType == "FileMoniker")
                    {
                        System.Runtime.InteropServices.ComTypes.FILETIME ft;
                        table.GetTimeOfLastChange(lst[0], out ft);
                        long     hFT2 = (((long)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
                        DateTime dte  = DateTime.FromFileTime(hFT2);
                        item.lastChange = dte;
                        //http://snipplr.com/view/32409/
                    }
                    if (item.monikerDetails.monikerType == "ItemMoniker")
                    {
                        string coreGuid = "";
                        {
                            if (item.displayName.Substring(0, 1) == "!")
                            {
                                coreGuid = item.displayName.Substring(1, 38);
                                RegistryKey key = null;
                                key = Registry.ClassesRoot.OpenSubKey("CLSID\\" + coreGuid);
                                if (key == null)
                                {
                                    key = Registry.ClassesRoot.OpenSubKey("Wow6432Node\\CLSID\\" + coreGuid);
                                }
                                if (key != null)
                                {
                                    item.className = key.GetValue(null).ToString();
                                }
                            }
                        }
                    }
                }
                itemsList.Add(item);
            }
            return(itemsList.ToArray());
        }