Пример #1
0
        private void CrawlRegistry(RegistrySnapshot snapshot, RegistryKey baseKey, string subTree)
        {
            List <string> subKeyNames = new List <string>();

            try
            {
                using (RegistryKey key = baseKey.OpenSubKey(subTree))
                {
                    if (key != null)
                    {
                        snapshot.Keys.Add(new RegistrySnapshotKey(key));
                        subKeyNames.AddRange(key.GetSubKeyNames());
                    }
                }
            }
            catch (SecurityException)
            {
                // Ignore and keep going
            }

            foreach (string subKey in subKeyNames)
            {
                string subTreePath = !string.IsNullOrEmpty(subTree) ? subTree + @"\" + subKey : subKey;
                CrawlRegistry(snapshot, baseKey, subTreePath);
            }
        }
Пример #2
0
        /// <summary>
        /// Creates a <see cref="RegistrySnapshot" /> object representing the current state of the specified registry path.
        /// </summary>
        /// <returns>A <see cref="RegistrySnapshot" /> object.</returns>
        public RegistrySnapshot TakeSnapshot()
        {
            RegistrySnapshot snapshot = new RegistrySnapshot(RegistryHive, RegistryPath);

            using (RegistryKey baseKey = _registryHives[RegistryHive])
            {
                CrawlRegistry(snapshot, baseKey, RegistryPath);
            }
            return(snapshot);
        }