Ejemplo n.º 1
0
        private static bool GetCOMAddIn(object app, string addInProgId, out NativeMethods.COMAddIn comAddIn)
        {
            bool flag = false;

            comAddIn = (NativeMethods.COMAddIn)null;
            long num = -2147418111L;

            if (app != null)
            {
                Type type = app.GetType();
                try
                {
                    NativeMethods.COMAddIns comAddIns = (NativeMethods.COMAddIns)type.InvokeMember("COMAddIns", BindingFlags.GetProperty, (Binder)null, app, (object[])null);
                    if (comAddIns != null)
                    {
                        foreach (NativeMethods.COMAddIn comAddIn1 in (IEnumerable)comAddIns)
                        {
                            if (comAddIn1.ProgId == addInProgId)
                            {
                                comAddIn = comAddIn1;
                                if (comAddIn.Connect)
                                {
                                    flag = true;
                                    break;
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                catch (COMException ex)
                {
                    if ((long)ex.ErrorCode == num)
                    {
                        Globals.AddErrorMessage(Resources.RPC_E_CALL_REJECTED_MESSAGE);
                    }
                    else
                    {
                        Globals.AddException((Exception)ex);
                    }
                }
            }
            return(flag);
        }
Ejemplo n.º 2
0
        internal static NativeMethods.COMAddIn GetLoadedCOMAddInObjects(ref AddInData addInData)
        {
            addInData.IsRunning       = false;
            addInData.IsLoaded        = false;
            addInData.IsObjectExposed = false;
            object app = (object)null;

            NativeMethods.COMAddIn comAddIn = (NativeMethods.COMAddIn)null;
            addInData.IsRunning = ComAddInUtilities.GetRunningApplicationObject(addInData.HostName, out app);
            if (addInData.IsRunning)
            {
                addInData.IsLoaded = ComAddInUtilities.GetCOMAddIn(app, addInData.ProgId, out comAddIn);
                if (addInData.IsLoaded && comAddIn.Object != null)
                {
                    addInData.IsObjectExposed = true;
                }
            }
            return(comAddIn);
        }
Ejemplo n.º 3
0
        private void EnumerateRegisteredAddIns(RegistryKey regHive, string hostName)
        {
            string regHiveName      = (string)null;
            string officeRegKeyName = (string)null;
            NameValueCollection registeredFormRegions = (NameValueCollection)null;

            RegistryReader.GetAddInsRegHiveNames(regHive, hostName, out regHiveName, out officeRegKeyName);
            try
            {
                if (hostName == "Outlook" && this.scanFormRegions)
                {
                    registeredFormRegions = RegistryReader.ReadFormRegionRegistrations(regHive);
                }
                using (RegistryKey registryKey = regHive.OpenSubKey(officeRegKeyName))
                {
                    if (registryKey == null)
                    {
                        return;
                    }
                    foreach (string progId in registryKey.GetSubKeyNames())
                    {
                        bool isDllPathValid             = true;
                        NativeMethods.COMAddIn comAddIn = (NativeMethods.COMAddIn)null;
                        bool isValidRegistration        = true;
                        this.isUncPath       = false;
                        this.isHttpPath      = false;
                        Globals.ErrorMessage = (string)null;
                        AddInData addInData = new AddInData(hostName, regHiveName, progId);
                        if (this.progIdsFound.Contains(addInData.ProgId))
                        {
                            addInData.StatusDescription = Resources.REGISTERED_MULTIPLE_TIMES;
                        }
                        else
                        {
                            this.progIdsFound.Add(addInData.ProgId);
                        }
                        try
                        {
                            using (RegistryKey addInKey = registryKey.OpenSubKey(addInData.ProgId))
                            {
                                if (addInKey != null)
                                {
                                    addInData.GetData(addInKey, this.scanManagedInterfaces, this.scanNativeInterfaces, this.scanRemote, ref this.isUncPath, ref this.isHttpPath, ref isDllPathValid, ref isValidRegistration);
                                }
                                else
                                {
                                    addInData.SetInvalidAddInKey();
                                }
                                if (isValidRegistration)
                                {
                                    comAddIn = ComAddInUtilities.GetLoadedCOMAddInObjects(ref addInData);
                                    if (this.isHttpPath)
                                    {
                                        addInData.StatusDescription = Resources.HTTP_PARTIAL_INFORMATION;
                                    }
                                    else if (!this.scanRemote && this.isUncPath)
                                    {
                                        addInData.StatusDescription = Resources.REMOTE_NOT_SELECTED;
                                    }
                                    else if (addInData.AssemblyPath != null && isDllPathValid)
                                    {
                                        addInData.InstallDate = this.GetAddInInstallDate(addInData.AssemblyPath);
                                    }
                                    else
                                    {
                                        addInData.SetInvalidPath();
                                    }
                                    if (addInData.AssemblyPath != null && addInData.AssemblyPath.EndsWith(".deploy"))
                                    {
                                        addInData.AssemblyPath = addInData.AssemblyPath.Substring(0, addInData.AssemblyPath.IndexOf(".deploy"));
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Globals.AddException(ex);
                        }
                        if (Globals.ErrorMessage != null && Globals.ErrorMessage.Length > 0)
                        {
                            addInData.StatusDescription = !string.IsNullOrEmpty(addInData.StatusDescription) ? string.Format("{0} {1}", (object)addInData.StatusDescription, (object)Globals.ErrorMessage) : Globals.ErrorMessage;
                        }
                        if (this.scanDisabled)
                        {
                            addInData.ScanForDisabledItems();
                        }
                        if (addInData.HostName == "Outlook" && this.scanFormRegions)
                        {
                            addInData.ScanForFormRegions(registeredFormRegions);
                        }
                        this.gridProxy.AddDataRow(addInData);
                    }
                }
            }
            catch (Exception ex)
            {
                Globals.AddException(ex);
            }
        }