/// <param name="path"></param> /// <param name="hardwareID">enumerator-specific-device-id</param> /// <param name="deviceID"></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 var enumerator = PNPDriverIntegratorUtils.GetEnumeratorNameFromHardwareID(hardwareID); if (enumerator == "*") { return(string.Empty); // unsupported enumerator; } var deviceInstanceID = string.Empty; var hiveKey = new ExportedRegistryINI(path).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 compatibleIDsEntry = instanceKey.GetValue("CompatibleIDs", new string[0]); if (compatibleIDsEntry is string[]) { var compatibleIDs = (string[])compatibleIDsEntry; foreach (var 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); }
private void ProcessCopyFileDirective(PNPDriverINFFile pnpDriverInf, string sourceFileName, string destinationFileName) { var relativeSourcePath = PNPDriverIntegratorUtils.GetRelativeDirectoryPath(pnpDriverInf, sourceFileName, _architectureIdentifier); var fileToCopy = new FileToCopy(relativeSourcePath, sourceFileName, destinationFileName); if (!FileSystemUtils.IsFileExist(_driverDirectory.Path + fileToCopy.RelativeSourceFilePath)) { Console.WriteLine("Error: Missing file: " + _driverDirectory.Path + fileToCopy.RelativeSourceFilePath); Program.Exit(); } // actual copy will be performed later _driverFilesToCopy.Add(fileToCopy); }