public static bool GetApplicationBitness(ICatalog2 catalog, string partitionID, string applicationID)
        {
            ICatalogCollection partitions   = (ICatalogCollection)(catalog.GetCollection(CollectionName.Partitions));
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionID));

            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)applications.GetCollection(CollectionName.Components, applicationID);

            try
            {
                components.Populate();
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                throw Tool.CreateException(SR.GetString(SR.FailedToDetermineTheBitnessOfApplication, applicationID), ex);
            }
            ICatalogObject component = (ICatalogObject)(components.Item(0));

            return(IsBitness64bit(component));
        }
        static void MarkComponentAsPrivate(ICatalog2 catalog, string partitionID, string applicationID, string progid)
        {
            ICatalogCollection partitions   = (ICatalogCollection)(catalog.GetCollection(CollectionName.Partitions));
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionID));

            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)applications.GetCollection(CollectionName.Components, applicationID);

            try
            {
                components.Populate();
                for (int j = 0; j < components.Count(); j++)
                {
                    ICatalogObject component = (ICatalogObject)(components.Item(j));
                    if ((string)component.Name() == progid)
                    {
                        component.SetValue(PropertyName.IsPrivateComponent, true);
                        components.SaveChanges();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                ToolConsole.WriteWarning(SR.GetString(SR.FailedToMarkListenerComponentAsPrivateForApplication, progid, applicationID));
            }
        }
        static string GetPartitionIdForApplication(ICatalog2 catalog, string appId, bool notThrow)
        {
            string partitionId = null;

            try
            {
                partitionId = catalog.GetPartitionID(appId);
            }
            catch (COMException e)
            {
                if (!notThrow)
                {
                    throw Tool.CreateException(SR.GetString(SR.CouldNotGetPartition), e);
                }
                else if (e.ErrorCode == HR.COMADMIN_E_OBJECT_DOES_NOT_EXIST)
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.ApplicationNotFound, appId));
                }
                else
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CouldnotGetPartitionForApplication, appId, e.ErrorCode, e.Message));
                }
                return(null);
            }
            return(partitionId);
        }
예제 #4
0
        internal static ComCatalogObject FindApplication(Guid applicationId)
        {
            ICatalog2 catalog = (ICatalog2)(new xCatalog());

            ICatalogObject     appObject           = null;
            ICatalogCollection partitionCollection = null;

            try
            {
                partitionCollection = (ICatalogCollection)catalog.GetCollection(
                    "Partitions");
                partitionCollection.Populate();
            }
            catch (COMException comException)
            {
                if (comException.ErrorCode != HR.COMADMIN_E_PARTITIONS_DISABLED)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(comException);
                }
            }

            if (partitionCollection != null)
            {
                for (int i = 0; i < partitionCollection.Count(); i++)
                {
                    ICatalogObject partition;
                    partition = (ICatalogObject)partitionCollection.Item(i);

                    ICatalogCollection appCollection;
                    appCollection = (ICatalogCollection)partitionCollection.GetCollection(
                        "Applications",
                        partition.Key());
                    appCollection.Populate();

                    appObject = FindApplication(appCollection, applicationId);
                    if (appObject != null)
                    {
                        return(new ComCatalogObject(appObject, appCollection));
                    }
                }
            }
            else
            {
                ICatalogCollection appCollection;
                appCollection = (ICatalogCollection)catalog.GetCollection(
                    "Applications");
                appCollection.Populate();

                appObject = FindApplication(appCollection, applicationId);
                if (appObject != null)
                {
                    return(new ComCatalogObject(appObject, appCollection));
                }
            }

            return(null);
        }
        public static void InstallListener(Guid appid, string path, RuntimeVersions runtimeVersion)
        {
            string application = appid.ToString("B");
            string partitionId = null;


            ICatalog2 catalog = GetCatalog();

            partitionId = GetPartitionIdForApplication(catalog, application, false);

            // Search for the listener in this partition..
            bool   is64bit  = GetApplicationBitness(catalog, partitionId, application);
            Guid   clsidVal = Guid.NewGuid();
            string clsid    = clsidVal.ToString("B");
            string tlb      = Path.Combine(path, application + "." + clsid + ".tlb");

            try
            {
                // No other listener in this partition, we're the first - install using RegistrationHelper
                AtomicFile.SafeDeleteFile(tlb);
                string modulePath = GetAppropriateBitnessModuleModulePath(is64bit, runtimeVersion);
                if (string.IsNullOrEmpty(modulePath))
                {
                    throw Tool.CreateException(SR.GetString(SR.CannotFindServiceInitializerModuleInRegistry), null);
                }
                CreateTypeLib(tlb, clsidVal);
                CreateRegistryKey(is64bit, clsidVal, modulePath);
                catalog.InstallComponent(application, modulePath, tlb, null);
                MarkComponentAsPrivate(catalog, partitionId, application, ListenerWSUName);
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.Description, ListenerComponentDescription))
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotSetComponentDescription, clsid, appid.ToString("B")));
                }
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.InitializesServerApplication, "1"))
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotSetComponentInitializerProperty, ListenerWSUName, appid.ToString("B")));
                }
                if (!SetComponentProperty(application, ListenerWSUName, PropertyName.ComponentAccessChecksEnabled, "0"))
                {
                    ToolConsole.WriteWarning(SR.GetString(SR.CannotDisableAccessChecksOnInitializer, ListenerWSUName, appid.ToString("B")));
                }
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                throw Tool.CreateException(SR.GetString(SR.CouldNotInstallListener), ex);
            }
            finally
            {
                AtomicFile.SafeDeleteFile(tlb);
            }
        }
 static void SetCurrentPartition(ICatalog2 catalog, string partitionId)
 {
     try
     {
         catalog.CurrentPartition(partitionId);
     }
     catch (Exception e)
     {
         if (e is NullReferenceException || e is SEHException)
         {
             throw e;
         }
         throw Tool.CreateException(SR.GetString(SR.CouldNotSetPartition), e);
     }
 }
        // returns true if deleted
        static bool RemoveComponent(ICatalog2 catalog, string partitionId, string applicationId, string progid)
        {
            int deleteIndex = -1;
            ICatalogCollection partitions = (ICatalogCollection)catalog.GetCollection(CollectionName.Partitions);

            partitions.Populate();
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionId));

            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)(applications.GetCollection(CollectionName.Components, applicationId));

            try
            {
                components.Populate();
                bool   is64bit = false;
                string clsid   = null;
                for (int i = 0; i < components.Count(); i++)
                {
                    ICatalogObject comp = (ICatalogObject)components.Item(i);
                    if (((string)comp.Name()).ToLowerInvariant() == progid.ToLowerInvariant())
                    {
                        clsid       = ((string)comp.Key()).ToLowerInvariant();
                        is64bit     = IsBitness64bit(comp);
                        deleteIndex = i;
                        break;
                    }
                }
                if (deleteIndex == -1)
                {
                    return(false);
                }

                components.Remove(deleteIndex);
                components.SaveChanges();
                RemoveClsidFromRegistry(is64bit, clsid);
            }
            catch (Exception e)
            {
                if (e is NullReferenceException || e is SEHException)
                {
                    throw e;
                }
                ToolConsole.WriteWarning(SR.GetString(SR.FailedToRemoveListenerComponentFromApplication, applicationId, progid));
            }
            return(true);
        }
        public static bool RemoveListener(Guid appid)
        {
            string application = appid.ToString("B");
            string partitionId = null;
            Guid   listenerClsid;
            string listenerProgid;

            ICatalog2 catalog = GetCatalog();

            partitionId = GetPartitionIdForApplication(catalog, application, false);
            bool is64bit = GetApplicationBitness(catalog, partitionId, application);

            if (FindListener(appid, out listenerClsid, out listenerProgid))
            {
                return(RemoveComponent(catalog, partitionId, application, listenerProgid));
            }
            return(false);
        }
        static bool FindApplication(string appidOrName, out ICatalogObject targetAppObj, out ICatalogCollection appColl)
        {
            targetAppObj = null;
            appColl      = null;

            bool      found       = false;
            ICatalog2 catalog     = GetCatalog();
            string    partitionId = null;

            partitionId = GetPartitionIdForApplication(catalog, appidOrName, true);
            if (!string.IsNullOrEmpty(partitionId))
            {
                SetCurrentPartition(catalog, partitionId);
            }

            appColl = (ICatalogCollection)(catalog.GetCollection(CollectionName.Applications));
            appColl.Populate();

            for (int i = 0; i < appColl.Count(); i++)
            {
                ICatalogObject appObj = (ICatalogObject)(appColl.Item(i));
                string         id     = ((string)appObj.Key()).ToLowerInvariant();
                string         name   = ((string)appObj.Name()).ToLowerInvariant();
                appidOrName = appidOrName.ToLowerInvariant();

                if (!found)
                {
                    if ((appidOrName == id) || (appidOrName == name))
                    {
                        found        = true;
                        targetAppObj = appObj;
                    }
                }
                else
                {
                    if ((appidOrName == id) || (appidOrName == name))
                    {
                        throw Tool.CreateException(SR.GetString(SR.AmbiguousApplicationName, appidOrName), null);
                    }
                }
            }

            return(found);
        }
        public static bool IsApplicationWow(Guid appid)
        {
            if (IntPtr.Size == 8)
            {
                string application = appid.ToString("B");
                string partitionId = null;


                ICatalog2 catalog = GetCatalog();
                partitionId = GetPartitionIdForApplication(catalog, application, false);

                // Search for the listener in this partition..
                bool is64bit = GetApplicationBitness(catalog, partitionId, application);

                return(!is64bit);
            }
            else
            {
                return(false);
            }
        }
        public static Guid[] GetApplicationIds()
        {
            ICatalog2   catalog = GetCatalog();
            List <Guid> appIds  = new List <Guid>();

            ICatalogCollection partitions = (ICatalogCollection)(catalog.GetCollection(CollectionName.Partitions));

            partitions.Populate();

            for (int i = 0; i < partitions.Count(); i++)
            {
                ICatalogObject     partition    = (ICatalogObject)(partitions.Item(i));
                ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partition.Key()));
                applications.Populate();

                for (int j = 0; j < applications.Count(); j++)
                {
                    ICatalogObject obj = (ICatalogObject)(applications.Item(j));
                    appIds.Add(new Guid((string)obj.Key()));
                }
            }
            return(appIds.ToArray());
        }
        public static string GetPartitionIdForApplication(Guid appId)
        {
            ICatalog2 catalog = GetCatalog();

            return(GetPartitionIdForApplication(catalog, appId.ToString("B"), true));
        }
예제 #13
0
 static string GetPartitionIdForApplication(ICatalog2 catalog, string appId, bool notThrow)
 {
     string partitionId = null;
     try
     {
         partitionId = catalog.GetPartitionID(appId);
     }
     catch (COMException e)
     {
         if (!notThrow)
             throw Tool.CreateException(SR.GetString(SR.CouldNotGetPartition), e);
         else if (e.ErrorCode == HR.COMADMIN_E_OBJECT_DOES_NOT_EXIST)
             ToolConsole.WriteWarning(SR.GetString(SR.ApplicationNotFound, appId));
         else
             ToolConsole.WriteWarning(SR.GetString(SR.CouldnotGetPartitionForApplication, appId, e.ErrorCode, e.Message));
         return null;
     }
     return partitionId;
 }
예제 #14
0
        public static bool GetApplicationBitness(ICatalog2 catalog, string partitionID, string applicationID)
        {
            ICatalogCollection partitions = (ICatalogCollection)(catalog.GetCollection(CollectionName.Partitions));
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionID));
            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)applications.GetCollection(CollectionName.Components, applicationID);
            try
            {
                components.Populate();
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                throw Tool.CreateException(SR.GetString(SR.FailedToDetermineTheBitnessOfApplication, applicationID), ex);
            }
            ICatalogObject component = (ICatalogObject)(components.Item(0));
            return IsBitness64bit(component);

        }
예제 #15
0
        static void MarkComponentAsPrivate(ICatalog2 catalog, string partitionID, string applicationID, string progid)
        {
            ICatalogCollection partitions = (ICatalogCollection)(catalog.GetCollection(CollectionName.Partitions));
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionID));
            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)applications.GetCollection(CollectionName.Components, applicationID);
            try
            {
                components.Populate();
                for (int j = 0; j < components.Count(); j++)
                {
                    ICatalogObject component = (ICatalogObject)(components.Item(j));
                    if ((string)component.Name() == progid)
                    {
                        component.SetValue(PropertyName.IsPrivateComponent, true);
                        components.SaveChanges();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex is NullReferenceException || ex is SEHException)
                {
                    throw ex;
                }

                ToolConsole.WriteWarning(SR.GetString(SR.FailedToMarkListenerComponentAsPrivateForApplication, progid, applicationID));
            }

        }
예제 #16
0
        // returns true if deleted
        static bool RemoveComponent(ICatalog2 catalog, string partitionId, string applicationId, string progid)
        {
            int deleteIndex = -1;
            ICatalogCollection partitions = (ICatalogCollection)catalog.GetCollection(CollectionName.Partitions);
            partitions.Populate();
            ICatalogCollection applications = (ICatalogCollection)(partitions.GetCollection(CollectionName.Applications, partitionId));
            applications.Populate();
            ICatalogCollection components = (ICatalogCollection)(applications.GetCollection(CollectionName.Components, applicationId));
            try
            {
                components.Populate();
                bool is64bit = false;
                string clsid = null;
                for (int i = 0; i < components.Count(); i++)
                {
                    ICatalogObject comp = (ICatalogObject)components.Item(i);
                    if (((string)comp.Name()).ToLowerInvariant() == progid.ToLowerInvariant())
                    {
                        clsid = ((string)comp.Key()).ToLowerInvariant();
                        is64bit = IsBitness64bit(comp);
                        deleteIndex = i;
                        break;
                    }
                }
                if (deleteIndex == -1)
                {
                    return false;
                }

                components.Remove(deleteIndex);
                components.SaveChanges();
                RemoveClsidFromRegistry(is64bit, clsid);

            }
            catch (Exception e)
            {
                if (e is NullReferenceException || e is SEHException)
                {
                    throw e;
                }
                ToolConsole.WriteWarning(SR.GetString(SR.FailedToRemoveListenerComponentFromApplication, applicationId, progid));
            }
            return true;
        }
예제 #17
0
        internal static void UninstallUtilityApplication(Type t)
        {
            DBG.Info(DBG.Registration, "Starting utility uninstallation:");

            try
            {
                if (Platform.IsLessThan(Platform.W2K))
                {
                    return;
                }

                ICatalog           cat  = null;
                ICatalogCollection apps = null;
                ICatalogObject     app  = null;
                int appidx = 0;

                cat = (ICatalog)(new xCatalog());

                if (!Platform.IsLessThan(Platform.Whistler))
                {
                    // AS/URT 97116:  Keep this from failing the install if
                    // we're on a Beta2 Whistler machine, which has a different
                    // GUID for ICatalog2.
                    ICatalog2 cat2 = cat as ICatalog2;
                    if (cat2 != null)
                    {
                        cat2.CurrentPartition(cat2.GlobalPartitionID());
                    }
                }

                apps = (ICatalogCollection)(cat.GetCollection("Applications"));
                RegistrationDriver.Populate(apps);

                app = FindApplication(apps, _appid, ref appidx);
                if (app != null)
                {
                    // Make sure that we can change this puppy:
                    app.SetValue("Changeable", true);
                    app.SetValue("Deleteable", true);
                    apps.SaveChanges();

                    DBG.Info(DBG.Registration, "Found application!");
                    int  idx = 0, compcount = 0;
                    Guid clsid = Marshal.GenerateGuidForType(typeof(RegistrationHelperTx));
                    ICatalogCollection comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key()));
                    ICatalogObject     comp  = FindComponent(comps, clsid, ref idx);
                    // Store count here, if it is 1, we can delete the app later.
                    compcount = comps.Count();
                    if (comp != null)
                    {
                        DBG.Info(DBG.Registration, "Found component at " + idx);
                        comps.Remove(idx);
                        comps.SaveChanges();
                    }

                    if (comp != null && compcount == 1)
                    {
                        DBG.Info(DBG.Registration, "Removing .NET Utilities application.");
                        // we removed the last component, kill the app
                        apps.Remove(appidx);
                        apps.SaveChanges();
                    }
                    else
                    {
                        // Make sure that we can't change the app:
                        app.SetValue("Changeable", false);
                        app.SetValue("Deleteable", false);
                        apps.SaveChanges();
                    }
                }
            }
            catch (Exception e)
            {
                // Log a failure in some acceptable manner.
                try
                {
                    EventLog appLog = new EventLog();
                    appLog.Source = "System.EnterpriseServices";
                    String errMsg = String.Format(Resource.FormatString("Reg_ErrUninstSysEnt"), e);
                    appLog.WriteEntry(errMsg, EventLogEntryType.Error);
                }
                catch
                {}

                // We threw an exception?  What do we do here?
                //DBG.Assert(false,
                //           "Installation of System.EnterpriseServices threw an exception!",
                //           "Exception: " + e);
                DBG.Info(DBG.Registration, "Caught exception: " + e);
            }
        }
예제 #18
0
 static void SetCurrentPartition(ICatalog2 catalog, string partitionId)
 {
     try
     {
         catalog.CurrentPartition(partitionId);
     }
     catch (Exception e)
     {
         if (e is NullReferenceException || e is SEHException)
         {
             throw e;
         }
         throw Tool.CreateException(SR.GetString(SR.CouldNotSetPartition), e);
     }
 }
        public static string GetGlobalPartitionID()
        {
            ICatalog2 catalog = GetCatalog();

            return(catalog.GlobalPartitionID());
        }
예제 #20
0
        internal static void InstallUtilityApplication(Type t)
        {
            DBG.Info(DBG.Registration, "Starting utility installation:");

            try
            {
                if (Platform.IsLessThan(Platform.W2K))
                {
                    return;
                }

                ICatalog           cat  = null;
                ICatalogCollection apps = null;
                ICatalogObject     app  = null;
                int junk = 0;

                cat = (ICatalog)(new xCatalog());

                if (!Platform.IsLessThan(Platform.Whistler))
                {
                    // AS/URT 97116:  Keep this from failing the install if
                    // we're on a Beta2 Whistler machine, which has a different
                    // GUID for ICatalog2.
                    ICatalog2 cat2 = cat as ICatalog2;

                    if (cat2 != null)
                    {
                        cat2.CurrentPartition(cat2.GlobalPartitionID());
                    }
                }

                apps = (ICatalogCollection)(cat.GetCollection("Applications"));
                RegistrationDriver.Populate(apps);

                app = FindApplication(apps, _appid, ref junk);
                if (app == null)
                {
                    DBG.Info(DBG.Registration, "Didn't find existing application...");
                    app = (ICatalogObject)(apps.Add());
                    app.SetValue("Name", _appname);
                    app.SetValue("Activation", ActivationOption.Library);
                    app.SetValue("ID", "{" + _appid.ToString() + "}");
                    if (!Platform.IsLessThan(Platform.Whistler))
                    {
                        // AS/URT 97116:  Keep this from failing the install if
                        // we're on a Beta2 Whistler machine, which has no Replicable property.
                        try
                        {
                            app.SetValue("Replicable", 0);
                        }
                        catch (Exception) {}
                    }
                    apps.SaveChanges();
                }
                else
                {
                    // Make sure that we can change this puppy:
                    app.SetValue("Changeable", true);
                    app.SetValue("Deleteable", true);
                    apps.SaveChanges();
                    app.SetValue("Name", _appname);
                    if (!Platform.IsLessThan(Platform.Whistler))
                    {
                        // AS/URT 97116:  Keep this from failing the install if
                        // we're on a Beta2 Whistler machine, which has no Replicable property.
                        try
                        {
                            app.SetValue("Replicable", 0);
                        }
                        catch (Exception) {}
                    }
                    apps.SaveChanges();
                }

                // Import ourselves into the application:
                Guid clsid = Marshal.GenerateGuidForType(typeof(RegistrationHelperTx));
                ICatalogCollection comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key()));
                ICatalogObject     comp  = FindComponent(comps, clsid, ref junk);
                if (comp == null)
                {
                    cat.ImportComponent("{" + _appid + "}", "{" + clsid + "}");
                    comps = (ICatalogCollection)(apps.GetCollection("Components", app.Key()));
                    comp  = FindComponent(comps, clsid, ref junk);
                }
                DBG.Assert(comp != null, "Couldn't find imported component!");

                ConfigureComponent(comps, comp);

                // And finally, lock this guy down:
                app.SetValue("Changeable", false);
                app.SetValue("Deleteable", false);
                apps.SaveChanges();

                DBG.Info(DBG.Registration, "Registering Proxy/Stub dlls:");
                Thunk.Proxy.RegisterProxyStub();


                // HACK
                // This is a HACK to get Windows XP Client COM+ export/import functionallity to work.
                // Export code will try to export System.EnterpriseServices.Thunk.dll because its not in it's
                // list of non-redist dlls.
                // We should get rid of this once this name is in the harcoded list in the export code.
                RegistryPermission rp = new RegistryPermission(PermissionState.Unrestricted);
                rp.Demand();
                rp.Assert();

                RegistryKey rk = Registry.LocalMachine.CreateSubKey("SOFTWARE\\MICROSOFT\\OLE\\NONREDIST");
                rk.SetValue("System.EnterpriseServices.Thunk.dll", "");
                rk.Close();
                // END HACK
            }
            catch (Exception e)
            {
                // Log a failure in some acceptable manner.
                try
                {
                    EventLog appLog = new EventLog();
                    appLog.Source = "System.EnterpriseServices";
                    String errMsg = String.Format(Resource.FormatString("Reg_ErrInstSysEnt"), e);
                    appLog.WriteEntry(errMsg, EventLogEntryType.Error);
                }
                catch
                {}

                // We threw an exception?  What do we do here?
                //DBG.Assert(false,
                //           "Installation of System.EnterpriseServices threw an exception!",
                //           "Exception: " + e);
            }
        }