示例#1
0
        private void RootCombo2_SelectedIndexChanged(object sender, EventArgs e)
        {
            rootCombo3.Items.Clear();
            rootCombo3.Text = "";

            RegistryKeyUtils.PopulateRootCombo3(rootCombo, rootCombo2, rootCombo3);
        }
示例#2
0
        private void RootCombo2_Changed(object sender, EventArgs e)
        {
            comboGeneralRegistryKeyRoot3.Items.Clear();
            comboGeneralRegistryKeyRoot3.Text = "";

            RegistryKeyUtils.PopulateRootCombo3(comboGeneralRegistryKeyRoot, comboGeneralRegistryKeyRoot2, comboGeneralRegistryKeyRoot3);
        }
示例#3
0
 private void checkButton_Click(object sender, EventArgs e)
 {
     if (_allowFeatureUsageLogging)
     {
         ExceptionlessClient.Default.SubmitFeatureUsage(Constants.FeatureUsages.RegistryKeyValueChecked);
     }
     RegistryKeyUtils.CheckCurrentKeyValue(CreateRegistryKeyStruct());
 }
        /// <param name="hardwareID">enumerator-specific-device-id</param>
        public static string DetectExportedDeviceInstanceID(string path, string hardwareID, out string deviceID)
        {
            Console.WriteLine("Searching for '" + hardwareID + "' in " + path);
            deviceID = String.Empty; // sometimes the device presents longer hardware ID than the one specified in the driver

            string enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(hardwareID);

            if (enumerator == "*")
            {
                return(String.Empty); // unsupported enumerator;
            }

            string deviceInstanceID     = String.Empty;
            ExportedRegistryKey hiveKey = new ExportedRegistry(path).LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum" + enumerator);

            foreach (string deviceKeyName in hiveKey.GetSubKeyNames())
            {
                ExportedRegistryKey deviceKey = hiveKey.OpenSubKey(deviceKeyName);
                if (deviceKey != null)
                {
                    foreach (string instanceKeyName in deviceKey.GetSubKeyNames())
                    {
                        ExportedRegistryKey instanceKey = deviceKey.OpenSubKey(instanceKeyName);
                        if (instanceKey != null)
                        {
                            object compatibleIDsEntry = instanceKey.GetValue("CompatibleIDs", new string[0]);
                            if (compatibleIDsEntry is string[])
                            {
                                string[] compatibleIDs = (string[])compatibleIDsEntry;

                                foreach (string compatibleID in compatibleIDs)
                                {
                                    if (compatibleID.Equals(hardwareID, StringComparison.InvariantCultureIgnoreCase))
                                    {
                                        deviceID         = RegistryKeyUtils.GetShortKeyName(deviceKey.Name);
                                        deviceInstanceID = RegistryKeyUtils.GetShortKeyName(instanceKey.Name);
                                        // Irrelevant Note: if a device is present but not installed in Windows then ConfigFlags entry will not be present
                                        // and it doesn't matter anyway because we don't care about how existing installation configure the device

                                        // there are two reasons not to use DeviceDesc from the local machine:
                                        // 1. on Windows 6.0+ (or just Windows PE?) the format is different and not compatible with Windows 5.x
                                        // 2. If the hadrware is present but not installed, the DeviceDesc will be a generic description (e.g. 'Ethernet Controller')

                                        Console.WriteLine("Found matching device: '" + deviceID + "'");
                                        return(deviceInstanceID);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(deviceInstanceID);
        }
示例#5
0
        private void checkButton_Click(object sender, EventArgs e)
        {
            var rootValue = RegistryKeyUtils.GetCurrentRoot(CreateRegistryKeyStruct());

            MessageBox.Show($"{Constants.RegistryKeyMessages.CurrentSelectedKey}" +
                            $"{rootValue}\\{fieldTextBox.Text}" +
                            $"{Constants.RegistryKeyMessages.CurrentValueOfKey}" +
                            $"{GetCurrentKeyValue()}",
                            Constants.RegistryKeyMessages.CurrentValueOfKeyCaption,
                            MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
示例#6
0
        private void LoadGeneralTab()
        {
            if (tabControl.SelectedTab != tabGeneral)
            {
                return;
            }

            SetupButtonEnabled(false);
            RegistryKeyUtils.PopulateComboBoxesBasedOnCurrentRegistryKey(_loadedSettings.MonitoredRegistryKey, CreateRegistryKeyObjectStruct());
            GlobalHotkeyUtils.PopulateGlobalHotkeyCombos(_loadedSettings.General.LoadedGlobalHotkey, CreateGlobalHotkeyObjectStruct());
            checkGeneralShowBalloonTips.Checked = _loadedSettings.General.ShowBalloonTips;
            GeneralUtils.PopulateIconProperties(_loadedSettings.General, comboGeneralIconFont, comboGeneralIconColor, comboGeneralIconTextColor);
            upDownGeneralIconSize.Text = _loadedSettings.General.IconFontSize.ToString(CultureInfo.InvariantCulture);

            // Check to see if Registry Monitor Starts With Windows
            checkGeneralStartWithWindows.Checked = rkStartup.GetValue(REGISTRY_MONITOR) != null;
        }
示例#7
0
        /*
         * public string FindVirtualDeviceInstanceID(string deviceClassName, string hardwareIDToFind)
         * {
         *      string result = string.Empty;
         *      string keyName = @"ControlSet001\Enum\Root\" + deviceClassName;
         *      if (m_isLoaded)
         *      {
         *              RegistryKey hiveKey = Registry.Users.OpenSubKey(m_hiveKeyName);
         *              RegistryKey key = hiveKey.OpenSubKey(keyName);
         *
         *              List<string> deviceInstanceIDs = new List<string>(key.GetSubKeyNames());
         *              foreach (string deviceInstanceID in deviceInstanceIDs)
         *              {
         *                      RegistryKey deviceInstanceKey = key.OpenSubKey(deviceInstanceID);
         *                      object hardwareIDEntry = deviceInstanceKey.GetValue("HardwareID", new string[0]);
         *                      if (hardwareIDEntry is string[])
         *                      {
         *                              string hardwareID = ((string[])hardwareIDEntry)[0];
         *                              if (string.Equals(hardwareID, hardwareIDToFind, StringComparison.InvariantCultureIgnoreCase))
         *                              {
         *                                      result = deviceInstanceID;
         *                                      break;
         *                              }
         *                      }
         *                      deviceInstanceKey.Close();
         *              }
         *              key.Close();
         *              hiveKey.Close();
         *              return result;
         *      }
         *      else
         *      {
         *              throw new Exception("Registry hive is not loaded");
         *      }
         * }
         */

        public void LoadHiveFromDirectory(string directory)
        {
            _hivePath = directory + FileName;
            // GetTempPath() should end with backward slash:
            _tempHivePath = Path.GetTempPath() + FileName;

            try
            {
                File.Copy(_hivePath, _tempHivePath, true);
            }
            catch
            {
                // perhaps the hive is already loaded from a previous crash / break
                // let's try to unload it
                RegistryUtils.UnloadHive(HiveKeyName);
                ProgramUtils.CopyCriticalFile(_hivePath, _tempHivePath);
                // CopyCriticalFile will exit the program on failue
            }

            var result = RegistryUtils.LoadHive(HiveKeyName, _tempHivePath);

            _isLoaded = (result == 0);
            if (!_isLoaded)
            {
                Console.WriteLine("Error: failed to load registry hive '{0}', error code: {1}", FileName, result);
                Console.WriteLine("This may happen due to one of the following reasons:");
                Console.WriteLine("- You do not have access to perform this operation");
                Console.WriteLine("- The hive is already loaded and needs to be manually unloaded (HKEY_USERS\\setupreg)");
                Environment.Exit(-1);
            }
            else
            {
                // if ControlSet001\Enum exist, its permissions will stick and stay for GUI-Mode \ final windows,
                // The default windows permissions for CurrentControlSet\Enum are:
                // SYSTEM   -> Full Control
                // Everyone -> Read
                // so we must make sure the default permissions are granted.
                const string subKeyName = HiveKeyName + @"\ControlSet001\Enum";
                // we're creating or opening the Enum key (if it's already exist, the permissions will simply be overwritten)
                // Note that we're creating ControlSet001\Enum even if we're not using it.
                var enumKey = Registry.Users.CreateSubKey(subKeyName, RegistryKeyPermissionCheck.ReadWriteSubTree);
                enumKey.Close();
                RegistryKeyUtils.SetHKeyUsersKeySecutiryDescriptor(subKeyName, RegistryKeyUtils.DesiredEnumSecurityDescriptorString);
            }
        }
示例#8
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            var keyValue = GetCurrentKeyValue();

            if (keyValue == string.Empty)
            {
                MessageBox.Show(Constants.RegistryKeyMessages.SelectRegistryKey,
                                Constants.RegistryKeyMessages.SelectRegistryKeyCaption,
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                var newRegistryKey = new Files.MonitoredRegistryKey
                {
                    Root   = RegistryKeyUtils.GetCurrentRoot(CreateRegistryKeyStruct()),
                    Subkey = fieldTextBox.Text
                };
                _loadedSettings.MonitoredRegistryKey = newRegistryKey;
                Close();
            }
        }
        /// <param name="hardwareID">enumerator-specific-device-id</param>
        /// <param name="deviceID"></param>
        public static string DetectLocalDeviceInstanceID(string hardwareID, out string deviceID)
        {
            Console.WriteLine("Searching for '" + hardwareID + "' on local machine");
            deviceID = string.Empty;             // sometimes the device presents longer hardware ID than the one specified in the driver

            var enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(hardwareID);

            if (enumerator == "*")
            {
                return(string.Empty);                // unsupported enumerator;
            }
            var deviceInstanceID = string.Empty;
            var hiveKey          = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Enum\" + enumerator);

            foreach (var deviceKeyName in hiveKey.GetSubKeyNames())
            {
                var deviceKey = hiveKey.OpenSubKey(deviceKeyName);
                if (deviceKey != null)
                {
                    foreach (var instanceKeyName in deviceKey.GetSubKeyNames())
                    {
                        var instanceKey = deviceKey.OpenSubKey(instanceKeyName);
                        if (instanceKey != null)
                        {
                            var hardwareIDs = new List <string>();

                            var hardwareIDEntry = instanceKey.GetValue("HardwareID", new string[0]);
                            if (hardwareIDEntry is string[])
                            {
                                hardwareIDs.AddRange((string[])hardwareIDEntry);
                            }

                            var compatibleIDsEntry = instanceKey.GetValue("CompatibleIDs", new string[0]);
                            if (compatibleIDsEntry is string[])
                            {
                                hardwareIDs.AddRange((string[])compatibleIDsEntry);
                            }

                            if (StringUtils.ContainsCaseInsensitive(hardwareIDs, hardwareID))
                            {
                                deviceID         = RegistryKeyUtils.GetShortKeyName(deviceKey.Name);
                                deviceInstanceID = RegistryKeyUtils.GetShortKeyName(instanceKey.Name);
                                // Irrelevant Note: if a device is present but not installed in Windows then ConfigFlags entry will not be present
                                // and it doesn't matter anyway because we don't care about how existing installation configure the device

                                // there are two reasons not to use DeviceDesc from the local machine:
                                // 1. on Windows 6.0+ (or just Windows PE?) the format is different and not compatible with Windows 5.x
                                // 2. If the hadrware is present but not installed, the DeviceDesc will be a generic description (e.g. 'Ethernet Controller')

                                Console.WriteLine("Found matching device: '" + deviceID + "'");
                                instanceKey.Close();
                                deviceKey.Close();
                                hiveKey.Close();
                                return(deviceInstanceID);
                            }

                            instanceKey.Close();
                        }
                    }
                    deviceKey.Close();
                }
            }

            hiveKey.Close();
            return(deviceInstanceID);
        }
示例#10
0
 private string GetCurrentKeyValue()
 {
     return((string)Registry.GetValue(RegistryKeyUtils.GetCurrentRoot(CreateRegistryKeyStruct()), fieldTextBox.Text, ""));
 }
示例#11
0
 private void AddRegistryKey_Load(object sender, EventArgs e)
 {
     RegistryKeyUtils.PopulateRootCombo(rootCombo);
 }