Esempio n. 1
0
        /// <summary>
        /// The default constructor takes a registry root path encoded as a string (for example, HKEY_LOCAL_MACHINE\Software\Microsoft)
        /// and reads everything under it.
        /// </summary>
        /// <param name="rootPath">Root path</param>
        /// <param name="registryView">Type of registry you want to see (32-bit, 64-bit, default).</param>
        public RegistryImporter(string rootPath, RegistryView registryView)
        {
            Result = new RegKeyEntry(null, rootPath);

            string      rootPathWithoutHive;
            RegistryKey rootKey = Regis3.OpenRegistryHive(rootPath, out rootPathWithoutHive, registryView);

            using (RegistryKey key = rootKey.OpenSubKey(rootPathWithoutHive))
            {
                ImportRecursive(Result, key);
            }
        }
        /// <summary>
        /// This constructor creates a registry importer for an existing registry key
        /// </summary>
        /// <param name="existingRegistry">Existing registry key</param>
        /// <param name="registryView">Type of registry you want to see (32-bit, 64-bit, default).</param>
        public RegistryImportRelativeToExistingRegKeyEntry(RegKeyEntry existingRegistry, RegistryView registryView)
        {
            Result = new RegKeyEntry(null, existingRegistry.Path);

            string      rootPath = existingRegistry.Path;
            string      rootPathWithoutHive;
            RegistryKey rootKey = Regis3.OpenRegistryHive(rootPath, out rootPathWithoutHive, registryView);

            using (RegistryKey key = rootKey.OpenSubKey(rootPathWithoutHive))
            {
                ImportRecursive(Result, key, existingRegistry);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Write the contents of this object back to the registry (possibly recursively)
        /// </summary>
        /// <param name="registryWriteOptions">Options for writing to the registry</param>
        /// <param name="env">Optional handler for environment variable replacement</param>
        /// <param name="registryView">Type of registry you want to see (32-bit, 64-bit, default).</param>
        public void WriteToTheRegistry(RegistryWriteOptions registryWriteOptions, RegEnvReplace env, RegistryView registryView)
        {
            if ((registryWriteOptions & RegistryWriteOptions.Recursive) != 0)
            {
                foreach (RegKeyEntry subkey in Keys.Values)
                {
                    subkey.WriteToTheRegistry(registryWriteOptions, env, registryView);
                }
            }

            string rootPath = env.Map(Path);
            string rootPathWithoutHive;

            using (RegistryKey registryKey = Regis3.OpenRegistryHive(rootPath, out rootPathWithoutHive, registryView))
            {
                if ((registryWriteOptions & RegistryWriteOptions.AllAccessForEveryone) != 0)
                {
                    using (RegistryKey subkey = registryKey.CreateSubKey(rootPathWithoutHive,
                                                                         RegistryKeyPermissionCheck.ReadWriteSubTree, RegistryOptions.None, AllAccessForEveryone))
                    {
                        foreach (RegValueEntry regValueEntry in Values.Values)
                        {
                            regValueEntry.WriteToTheRegistry(subkey, env);
                        }
                        subkey.Close();
                    }
                }
                else
                {
                    using (RegistryKey subkey = registryKey.CreateSubKey(rootPathWithoutHive))
                    {
                        foreach (RegValueEntry regValueEntry in Values.Values)
                        {
                            regValueEntry.WriteToTheRegistry(subkey, env);
                        }
                        subkey.Close();
                    }
                }
            }
        }