Пример #1
0
        /// <include file='doc\PerformanceCounterInstaller.uex' path='docs/doc[@for="PerformanceCounterInstaller.DoRollback"]/*' />
        /// <devdoc>
        /// Restores the registry to how it was before install, as saved in the state dictionary.
        /// </devdoc>
        private void DoRollback(IDictionary state)
        {
            //we need to remove the category key OR put old data back into the key
            Context.LogMessage(Res.GetString(Res.RestoringPerformanceCounter, CategoryName));

            using (RegistryKey servicesKey = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services", true)) {
                RegistryKey categoryKey = null;

                if ((bool)state["categoryKeyExisted"])
                {
                    categoryKey = servicesKey.OpenSubKey(CategoryName, true);

                    if (categoryKey == null)
                    {
                        categoryKey = servicesKey.CreateSubKey(CategoryName);
                    }

                    categoryKey.DeleteSubKeyTree("Performance");
                    SerializableRegistryKey performanceKeyData = (SerializableRegistryKey)state["performanceKeyData"];
                    if (performanceKeyData != null)
                    {
                        RegistryKey performanceKey = categoryKey.CreateSubKey("Performance");
                        performanceKeyData.CopyToRegistry(performanceKey);
                        performanceKey.Close();
                    }

                    categoryKey.DeleteSubKeyTree("Linkage");
                    SerializableRegistryKey linkageKeyData = (SerializableRegistryKey)state["linkageKeyData"];
                    if (linkageKeyData != null)
                    {
                        RegistryKey linkageKey = categoryKey.CreateSubKey("Linkage");
                        linkageKeyData.CopyToRegistry(linkageKey);
                        linkageKey.Close();
                    }
                }
                else
                {
                    categoryKey = servicesKey.OpenSubKey(CategoryName);
                    if (categoryKey != null)
                    {
                        categoryKey.Close();
                        categoryKey = null;
                        servicesKey.DeleteSubKeyTree(CategoryName);
                    }
                }
                if (categoryKey != null)
                {
                    categoryKey.Close();
                }
            }
        }
Пример #2
0
        // Restores the registry to the state it was in when SaveRegistryKey ran.
        private void RestoreRegistryKey(SerializableRegistryKey serializable)
        {
            // A RegistryKey can't contain all the information necessary to serialize it,
            // so we have to have prior knowledge about where to put the saved information.
            // Luckily, we do. =)
            RegistryKey regKey = Registry.LocalMachine;

            regKey = regKey.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\EventLog", /*writable*/ true);
            regKey = regKey.CreateSubKey(Log);
            regKey = regKey.CreateSubKey(Source);

            serializable.CopyToRegistry(regKey);

            regKey.Close();
        }
 private void DoRollback(IDictionary state)
 {
     base.Context.LogMessage(Res.GetString("RestoringPerformanceCounter", new object[] { this.CategoryName }));
     using (RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services", true))
     {
         RegistryKey key2 = null;
         if ((bool)state["categoryKeyExisted"])
         {
             key2 = key.OpenSubKey(this.CategoryName, true);
             if (key2 == null)
             {
                 key2 = key.CreateSubKey(this.CategoryName);
             }
             key2.DeleteSubKeyTree("Performance");
             SerializableRegistryKey key3 = (SerializableRegistryKey)state["performanceKeyData"];
             if (key3 != null)
             {
                 RegistryKey baseKey = key2.CreateSubKey("Performance");
                 key3.CopyToRegistry(baseKey);
                 baseKey.Close();
             }
             key2.DeleteSubKeyTree("Linkage");
             SerializableRegistryKey key5 = (SerializableRegistryKey)state["linkageKeyData"];
             if (key5 != null)
             {
                 RegistryKey key6 = key2.CreateSubKey("Linkage");
                 key5.CopyToRegistry(key6);
                 key6.Close();
             }
         }
         else
         {
             key2 = key.OpenSubKey(this.CategoryName);
             if (key2 != null)
             {
                 key2.Close();
                 key2 = null;
                 key.DeleteSubKeyTree(this.CategoryName);
             }
         }
         if (key2 != null)
         {
             key2.Close();
         }
     }
 }
Пример #4
0
        /// <include file='doc\PerformanceCounterInstaller.uex' path='docs/doc[@for="PerformanceCounterInstaller.DoRollback"]/*' />
        /// <devdoc>
        /// Restores the registry to how it was before install, as saved in the state dictionary.
        /// </devdoc>
        private void DoRollback(IDictionary state)
        {
            //we need to remove the category key OR put old data back into the key
            Context.LogMessage(Res.GetString(Res.RestoringPerformanceCounter, CategoryName));

            SerializableRegistryKey categoryKeyData = (SerializableRegistryKey)state["categoryKeyData"];

            RegistryKey servicesKey = Registry.LocalMachine.CreateSubKey("SYSTEM\\CurrentControlSet\\Services");
            RegistryKey categoryKey = servicesKey.OpenSubKey(CategoryName);

            if (categoryKey != null)
            {
                categoryKey.Close();
                servicesKey.DeleteSubKeyTree(CategoryName);
            }
            //re-create key with old data ONLY if we had data saved into the hashtable
            if (categoryKeyData != null)
            {
                categoryKey = servicesKey.CreateSubKey(CategoryName);
                categoryKeyData.CopyToRegistry(categoryKey);
            }
        }