/// <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);
        }
        public static List <string> GetExportedHardwareCompatibleIDs(string path)
        {
            List <string>       result  = new List <string>();
            string              keyName = @"SYSTEM\CurrentControlSet\Enum";
            ExportedRegistryKey hiveKey = new ExportedRegistry(path).LocalMachine.OpenSubKey(keyName);

            foreach (string enumerator in hiveKey.GetSubKeyNames())
            {
                ExportedRegistryKey enumeratorKey = hiveKey.OpenSubKey(enumerator);
                if (enumeratorKey != null)
                {
                    foreach (string deviceKeyName in enumeratorKey.GetSubKeyNames())
                    {
                        ExportedRegistryKey deviceKey = enumeratorKey.OpenSubKey(deviceKeyName);
                        if (deviceKey != null)
                        {
                            foreach (string instanceKeyName in deviceKey.GetSubKeyNames())
                            {
                                ExportedRegistryKey instanceKey = deviceKey.OpenSubKey(instanceKeyName);
                                if (instanceKey != null)
                                {
                                    object hardwareIDEntry = instanceKey.GetValue("HardwareID", new string[0]);
                                    if (hardwareIDEntry is string[])
                                    {
                                        result.AddRange((string[])hardwareIDEntry);
                                    }

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

            return(result);
        }
Ejemplo n.º 3
0
 public ExportedRegistryKey(ExportedRegistry registry, string keyName)
 {
     m_registry = registry;
     m_keyName  = keyName;
 }