Esempio n. 1
0
        private void Register(RegistryCaptureKey key)
        {
            RegistryKey rootKey = null;

            switch (key.Root)
            {
            case Constants.Registry.Key.ClassesRoot:
                rootKey = Microsoft.Win32.Registry.ClassesRoot;
                break;

            case Constants.Registry.Key.CurrentUser:
                rootKey = Microsoft.Win32.Registry.CurrentUser;
                break;

            case Constants.Registry.Key.Users:
                rootKey = Microsoft.Win32.Registry.Users;
                break;

            case Constants.Registry.Key.LocalMachine:
                rootKey = Microsoft.Win32.Registry.LocalMachine;
                break;
            }

            // Create the key.

            if (rootKey != null)
            {
                RegistryKey registryKey = rootKey.CreateSubKey(key.RootRelativePath);

                // Iterate over values.

                foreach (RegistryCaptureValue value in key.Values)
                {
                    if (value is RegistryCaptureStringValue)
                    {
                        registryKey.SetValue(value.Name, value.Value, RegistryValueKind.String);
                    }
                    else if (value is RegistryCaptureDWordValue)
                    {
                        registryKey.SetValue(value.Name, value.Value, RegistryValueKind.DWord);
                    }
                    else if (value is RegistryCaptureBinaryValue)
                    {
                        registryKey.SetValue(value.Name, value.Value, RegistryValueKind.Binary);
                    }
                    else if (value is RegistryCaptureExpandStringValue)
                    {
                        registryKey.SetValue(value.Name, value.Value, RegistryValueKind.ExpandString);
                    }
                    else if (value is RegistryCaptureMultiStringValue)
                    {
                        registryKey.SetValue(value.Name, value.Value, RegistryValueKind.MultiString);
                    }
                    else
                    {
                        registryKey.SetValue(value.Name, value.Value);
                    }
                }
            }
        }
Esempio n. 2
0
        private static void ResolvePaths(RegistryCaptureKey key, string fileName, string fullPath)
        {
            // Iterate.

            foreach (RegistryCaptureKey subKey in key.SubKeys)
            {
                ResolvePaths(subKey, fileName, fullPath);
            }

            foreach (RegistryCaptureValue registryValue in key.Values)
            {
                // This is a dodgy test but will do for now.

                string value = registryValue.Value as string;
                if (value != null && value.EndsWith(fileName) && value != fileName)
                {
                    registryValue.Value = fullPath;
                }
            }
        }
Esempio n. 3
0
        private void Unregister(RegistryCaptureKey key)
        {
            RegistryKey rootKey = null;

            switch (key.Root)
            {
            case Constants.Registry.Key.ClassesRoot:
                rootKey = Microsoft.Win32.Registry.ClassesRoot;
                break;

            case Constants.Registry.Key.CurrentUser:
                rootKey = Microsoft.Win32.Registry.CurrentUser;
                break;

            case Constants.Registry.Key.Users:
                rootKey = Microsoft.Win32.Registry.Users;
                break;

            case Constants.Registry.Key.LocalMachine:
                rootKey = Microsoft.Win32.Registry.LocalMachine;
                break;
            }

            // Create the key.

            if (rootKey != null)
            {
                try
                {
                    rootKey.DeleteSubKeyTree(key.RootRelativePath);
                }
                catch (System.Exception)
                {
                }
            }
        }
Esempio n. 4
0
        private RegistryCaptureKey GetKey(RegistryKey key)
        {
            string path;
            int    pos = key.Name.IndexOf(m_rootKey);

            if (pos != -1)
            {
                path = key.Name.Substring(pos + m_rootKey.Length);
            }
            else
            {
                path = key.Name;
            }
            if (path.StartsWith("\\"))
            {
                path = path.Substring(1);
            }

            RegistryCaptureKey captureKey = new RegistryCaptureKey(path);

            // Iterate over all values.

            foreach (string name in key.GetValueNames())
            {
                switch (key.GetValueKind(name))
                {
                case RegistryValueKind.String:
                    captureKey.Add(new RegistryCaptureStringValue(name, key.GetValue(name) as string));
                    break;

                case RegistryValueKind.DWord:
                    captureKey.Add(new RegistryCaptureDWordValue(name, (int)key.GetValue(name)));
                    break;

                case RegistryValueKind.ExpandString:
                    captureKey.Add(new RegistryCaptureExpandStringValue(name, key.GetValue(name) as string));
                    break;

                case RegistryValueKind.MultiString:
                    captureKey.Add(new RegistryCaptureMultiStringValue(name, key.GetValue(name) as string[]));
                    break;

                case RegistryValueKind.Unknown:
                case RegistryValueKind.Binary:
                case RegistryValueKind.QWord:
                    captureKey.Add(new RegistryCaptureValue(name, key.GetValue(name)));
                    break;
                }
            }

            // Iterate over sub keys.

            foreach (string subKeyName in key.GetSubKeyNames())
            {
                using (RegistryKey subKey = key.OpenSubKey(subKeyName))
                {
                    captureKey.Add(GetKey(subKey));
                }
            }

            return(captureKey);
        }