private void UnregisterPrimaryInteropAssembly(Assembly assembly, PrimaryInteropAssemblyAttribute attr)
        {
            string str1    = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            int    num     = attr.MajorVersion;
            string string1 = num.ToString("x", (IFormatProvider)CultureInfo.InvariantCulture);
            string str2    = ".";

            num = attr.MinorVersion;
            string string2 = num.ToString("x", (IFormatProvider)CultureInfo.InvariantCulture);
            string str3    = string1 + str2 + string2;

            using (RegistryKey registryKey1 = Registry.ClassesRoot.OpenSubKey("TypeLib", true))
            {
                if (registryKey1 == null)
                {
                    return;
                }
                using (RegistryKey registryKey2 = registryKey1.OpenSubKey(str1, true))
                {
                    if (registryKey2 != null)
                    {
                        using (RegistryKey registryKey3 = registryKey2.OpenSubKey(str3, true))
                        {
                            if (registryKey3 != null)
                            {
                                registryKey3.DeleteValue("PrimaryInteropAssemblyName", false);
                                registryKey3.DeleteValue("PrimaryInteropAssemblyCodeBase", false);
                                if (registryKey3.SubKeyCount == 0)
                                {
                                    if (registryKey3.ValueCount == 0)
                                    {
                                        registryKey2.DeleteSubKey(str3);
                                    }
                                }
                            }
                        }
                        if (registryKey2.SubKeyCount == 0)
                        {
                            if (registryKey2.ValueCount == 0)
                            {
                                registryKey1.DeleteSubKey(str1);
                            }
                        }
                    }
                }
                if (registryKey1.SubKeyCount != 0 || registryKey1.ValueCount != 0)
                {
                    return;
                }
                Registry.ClassesRoot.DeleteSubKey("TypeLib");
            }
        }
        private void UnregisterPrimaryInteropAssembly(Assembly assembly, PrimaryInteropAssemblyAttribute attr)
        {
            String strTlbId   = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            String strVersion = attr.MajorVersion + "." + attr.MinorVersion;

            // Try to open the HKEY_CLASS_ROOT\TypeLib key.
            RegistryKey TypeLibRootKey = Registry.ClassesRoot.OpenSubKey("TypeLib", true);

            if (TypeLibRootKey != null)
            {
                // Try to open the HKEY_CLASS_ROOT\TypeLib\<TLBID> key.
                RegistryKey TypeLibKey = TypeLibRootKey.OpenSubKey(strTlbId);
                if (TypeLibKey != null)
                {
                    // Try to open the HKEY_CLASS_ROOT\TypeLib<TLBID>\<Major.Minor> key.
                    RegistryKey VersionKey = TypeLibKey.OpenSubKey(strVersion, true);
                    if (VersionKey != null)
                    {
                        // Delete the values we created.
                        VersionKey.DeleteValue("PrimaryInteropAssemblyName", false);
                        VersionKey.DeleteValue("PrimaryInteropAssemblyCodeBase", false);

                        // If there are no other values or subkeys then we can delete the VersionKey.
                        if ((VersionKey.SubKeyCount == 0) && (VersionKey.ValueCount == 0))
                        {
                            TypeLibKey.DeleteSubKey(strVersion);
                        }

                        // Close the key.
                        VersionKey.Close();
                    }

                    // If there are no other values or subkeys then we can delete the TypeLibKey.
                    if ((TypeLibKey.SubKeyCount == 0) && (TypeLibKey.ValueCount == 0))
                    {
                        TypeLibRootKey.DeleteSubKey(strTlbId);
                    }

                    // Close the TypeLibKey.
                    TypeLibKey.Close();
                }

                // Close the TypeLibRootKey.
                TypeLibRootKey.Close();
            }
        }
Beispiel #3
0
        private void UnregisterPrimaryInteropAssembly(Assembly assembly, PrimaryInteropAssemblyAttribute attr)
        {
            string text  = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            string text2 = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);

            using (RegistryKey registryKey = Registry.ClassesRoot.OpenSubKey("TypeLib", true))
            {
                if (registryKey != null)
                {
                    using (RegistryKey registryKey2 = registryKey.OpenSubKey(text, true))
                    {
                        if (registryKey2 != null)
                        {
                            using (RegistryKey registryKey3 = registryKey2.OpenSubKey(text2, true))
                            {
                                if (registryKey3 != null)
                                {
                                    registryKey3.DeleteValue("PrimaryInteropAssemblyName", false);
                                    registryKey3.DeleteValue("PrimaryInteropAssemblyCodeBase", false);
                                    if (registryKey3.SubKeyCount == 0 && registryKey3.ValueCount == 0)
                                    {
                                        registryKey2.DeleteSubKey(text2);
                                    }
                                }
                            }
                            if (registryKey2.SubKeyCount == 0 && registryKey2.ValueCount == 0)
                            {
                                registryKey.DeleteSubKey(text);
                            }
                        }
                    }
                    if (registryKey.SubKeyCount == 0 && registryKey.ValueCount == 0)
                    {
                        Registry.ClassesRoot.DeleteSubKey("TypeLib");
                    }
                }
            }
        }
Beispiel #4
0
        [System.Security.SecurityCritical]  // auto-generated
        private void UnregisterPrimaryInteropAssembly(Assembly assembly, PrimaryInteropAssemblyAttribute attr)
        {
            String strTlbId = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            String strVersion = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);

            // Try to open the HKEY_CLASS_ROOT\TypeLib key.
            using (RegistryKey TypeLibRootKey = Registry.ClassesRoot.OpenSubKey(strTlbRootName, true))
            {
                if (TypeLibRootKey != null)
                {
                    // Try to open the HKEY_CLASS_ROOT\TypeLib\<TLBID> key.
                    using (RegistryKey TypeLibKey = TypeLibRootKey.OpenSubKey(strTlbId, true))
                    {
                        if (TypeLibKey != null)
                        {
                            // Try to open the HKEY_CLASS_ROOT\TypeLib<TLBID>\<Major.Minor> key.
                            using (RegistryKey VersionSubKey = TypeLibKey.OpenSubKey(strVersion, true))
                            {
                                if (VersionSubKey != null)
                                {
                                    // Delete the values we created.
                                    VersionSubKey.DeleteValue("PrimaryInteropAssemblyName",false);
                                    VersionSubKey.DeleteValue("PrimaryInteropAssemblyCodeBase",false);

                                    // If there are no other values or subkeys then we can delete the VersionKey.
                                    if ((VersionSubKey.SubKeyCount == 0) && (VersionSubKey.ValueCount == 0))
                                        TypeLibKey.DeleteSubKey(strVersion);
                                }
                            }

                            // If there are no other values or subkeys then we can delete the TypeLibKey.
                            if ((TypeLibKey.SubKeyCount == 0) && (TypeLibKey.ValueCount == 0))
                                TypeLibRootKey.DeleteSubKey(strTlbId);                            
                        }
                    }

                    // If there are no other values or subkeys then we can delete the TypeLib key.
                    if ((TypeLibRootKey.SubKeyCount == 0) && (TypeLibRootKey.ValueCount == 0))
                        Registry.ClassesRoot.DeleteSubKey(strTlbRootName);                    
                }
            }
        }
Beispiel #5
0
        [System.Security.SecurityCritical]  // auto-generated
        private void RegisterPrimaryInteropAssembly(RuntimeAssembly assembly, String strAsmCodeBase, PrimaryInteropAssemblyAttribute attr)
        {
            // Validate that the PIA has a strong name.
            if (assembly.GetPublicKey().Length == 0)
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed"));

            String strTlbId = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            String strVersion = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);

            // Create the HKEY_CLASS_ROOT\TypeLib key.
            using (RegistryKey TypeLibRootKey = Registry.ClassesRoot.CreateSubKey(strTlbRootName))
            {
                // Create the HKEY_CLASS_ROOT\TypeLib\<TLBID> key.
                using (RegistryKey TypeLibKey = TypeLibRootKey.CreateSubKey(strTlbId))
                {
                    // Create the HKEY_CLASS_ROOT\TypeLib\<TLBID>\<Major.Minor> key.
                    using (RegistryKey VersionSubKey = TypeLibKey.CreateSubKey(strVersion))
                    {
                        // Create the HKEY_CLASS_ROOT\TypeLib\<TLBID>\PrimaryInteropAssembly key.
                        VersionSubKey.SetValue("PrimaryInteropAssemblyName", assembly.FullName);
                        if (strAsmCodeBase != null)
                            VersionSubKey.SetValue("PrimaryInteropAssemblyCodeBase", strAsmCodeBase);
                    }
                }
            }
        }
Beispiel #6
0
        private void RegisterPrimaryInteropAssembly(RuntimeAssembly assembly, string strAsmCodeBase, PrimaryInteropAssemblyAttribute attr)
        {
            if (assembly.GetPublicKey().Length == 0)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed"));
            }
            string subkey  = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            string subkey2 = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);

            using (RegistryKey registryKey = Registry.ClassesRoot.CreateSubKey("TypeLib"))
            {
                using (RegistryKey registryKey2 = registryKey.CreateSubKey(subkey))
                {
                    using (RegistryKey registryKey3 = registryKey2.CreateSubKey(subkey2))
                    {
                        registryKey3.SetValue("PrimaryInteropAssemblyName", assembly.FullName);
                        if (strAsmCodeBase != null)
                        {
                            registryKey3.SetValue("PrimaryInteropAssemblyCodeBase", strAsmCodeBase);
                        }
                    }
                }
            }
        }
        private void RegisterPrimaryInteropAssembly(Assembly assembly, String strAsmCodeBase, PrimaryInteropAssemblyAttribute attr)
        {
            // Validate that the PIA has a strong name.
            if (assembly.nGetPublicKey() == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed"));
            }

            String strTlbId   = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
            String strVersion = attr.MajorVersion + "." + attr.MinorVersion;

            // Create the HKEY_CLASS_ROOT\TypeLib<TLBID> key.
            RegistryKey TypeLibRootKey = Registry.ClassesRoot.CreateSubKey("TypeLib");
            RegistryKey TypeLibKey     = TypeLibRootKey.CreateSubKey(strTlbId);

            // Create the HKEY_CLASS_ROOT\TypeLib<TLBID>\<Major.Minor> key.
            RegistryKey VersionKey = TypeLibKey.CreateSubKey(strVersion);

            // Create the HKEY_CLASS_ROOT\TypeLib<TLBID>\PrimaryInteropAssembly key.
            VersionKey.SetValue("PrimaryInteropAssemblyName", assembly.FullName);
            if (strAsmCodeBase != null)
            {
                VersionKey.SetValue("PrimaryInteropAssemblyCodeBase", strAsmCodeBase);
            }

            // Close the registry keys.
            VersionKey.Close();
            TypeLibKey.Close();
            TypeLibRootKey.Close();
        }
 private void UnregisterPrimaryInteropAssembly(Assembly assembly, PrimaryInteropAssemblyAttribute attr)
 {
     string name = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
     string str2 = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);
     using (RegistryKey key = Registry.ClassesRoot.OpenSubKey("TypeLib", true))
     {
         if (key != null)
         {
             using (RegistryKey key2 = key.OpenSubKey(name, true))
             {
                 if (key2 != null)
                 {
                     using (RegistryKey key3 = key2.OpenSubKey(str2, true))
                     {
                         if (key3 != null)
                         {
                             key3.DeleteValue("PrimaryInteropAssemblyName", false);
                             key3.DeleteValue("PrimaryInteropAssemblyCodeBase", false);
                             if ((key3.SubKeyCount == 0) && (key3.ValueCount == 0))
                             {
                                 key2.DeleteSubKey(str2);
                             }
                         }
                     }
                     if ((key2.SubKeyCount == 0) && (key2.ValueCount == 0))
                     {
                         key.DeleteSubKey(name);
                     }
                 }
             }
             if ((key.SubKeyCount == 0) && (key.ValueCount == 0))
             {
                 Registry.ClassesRoot.DeleteSubKey("TypeLib");
             }
         }
     }
 }
 private void RegisterPrimaryInteropAssembly(RuntimeAssembly assembly, string strAsmCodeBase, PrimaryInteropAssemblyAttribute attr)
 {
     if (assembly.GetPublicKey().Length == 0)
     {
         throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_PIAMustBeStrongNamed"));
     }
     string subkey = "{" + Marshal.GetTypeLibGuidForAssembly(assembly).ToString().ToUpper(CultureInfo.InvariantCulture) + "}";
     string str2 = attr.MajorVersion.ToString("x", CultureInfo.InvariantCulture) + "." + attr.MinorVersion.ToString("x", CultureInfo.InvariantCulture);
     using (RegistryKey key = Registry.ClassesRoot.CreateSubKey("TypeLib"))
     {
         using (RegistryKey key2 = key.CreateSubKey(subkey))
         {
             using (RegistryKey key3 = key2.CreateSubKey(str2))
             {
                 key3.SetValue("PrimaryInteropAssemblyName", assembly.FullName);
                 if (strAsmCodeBase != null)
                 {
                     key3.SetValue("PrimaryInteropAssemblyCodeBase", strAsmCodeBase);
                 }
             }
         }
     }
 }