private void PreconfigureDeviceInstance(PNPDriverINFFile pnpDriverInf, ISystemRegistryHive systemRegistryHive, string enumerator, string deviceID, string deviceInstanceID, BaseDeviceService deviceService) { var driver = pnpDriverInf.ClassGUID.ToUpper() + @"\" + _classInstanceID; var manufacturerName = pnpDriverInf.GetDeviceManufacturerName(HardwareID, _installation.ArchitectureIdentifier, _installation.MinorOSVersion, _installation.ProductType); var hardwareKeyName = @"Enum\" + enumerator + @"\" + deviceID + @"\" + deviceInstanceID; systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "ClassGUID", RegistryValueKind.String, pnpDriverInf.ClassGUID); // The presence of DeviceDesc is critical for some reason, but any value can be used systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "DeviceDesc", RegistryValueKind.String, deviceService.DeviceDescription); // "Driver" is used to help Windows determine which software key belong to this hardware key. // Note: When re-installing the driver, the software key to be used will be determined by this value as well. systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "Driver", RegistryValueKind.String, driver); systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "Service", RegistryValueKind.String, deviceService.ServiceName); // ConfigFlags is not related to the hardware, it's the status of the configuration of the device by Windows (CONFIGFLAG_FAILEDINSTALL etc.) // the presence of this value tells windows the device has driver installed systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "ConfigFlags", RegistryValueKind.DWord, 0); if (PNPDriverINFFile.IsRootDevice(HardwareID)) { // Windows uses the "HardwareID" entry to determine if the hardware is already installed, // We don't have to add this value for physical devices, because Windows will get this value from the device, // but we must add this for virtual devices, or we will find ourselves with duplicity when re-installing (e.g. two Microsoft iScsi Initiators). systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "HardwareID", RegistryValueKind.MultiString, new[] { HardwareID }); } // not necessary: systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "Mfg", RegistryValueKind.String, manufacturerName); systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "Class", RegistryValueKind.String, pnpDriverInf.ClassName); }
public void IntegrateDriver() { PNPDriverINFFile pnpDriverInf; var installSectionName = DriverDirectory.GetDeviceInstallSectionName(HardwareID, _installation.ArchitectureIdentifier, _installation.MinorOSVersion, _installation.ProductType, out pnpDriverInf); if (installSectionName == string.Empty) { Console.WriteLine("Unable to locate InstallSectionName in INF file"); Program.Exit(); } _classInstanceID = _installation.SetupRegistryHive.AllocateClassInstanceID(pnpDriverInf.ClassGUID); ProcessInstallSection(pnpDriverInf, installSectionName, _classInstanceID); ProcessInstallServicesSection(pnpDriverInf, installSectionName); // this.DeviceServices is now populated if (DeviceServices.Count == 0) { Console.WriteLine("Error: driver does not have an associated service, IntegrateDrv will not proceed."); Program.Exit(); } PrepareToPreventTextModeDriverNameCollision(DeviceServices); foreach (var deviceService in DeviceServices) { InstructToLoadTextModeDeviceService(deviceService); RegisterDeviceService(_installation.SetupRegistryHive, pnpDriverInf, deviceService); RegisterDeviceService(_installation.HiveSystemInf, pnpDriverInf, deviceService); } CopyDriverFiles(DeviceServices); // register the device: if (PNPDriverINFFile.IsRootDevice(HardwareID)) { // installing virtual device: (this is critical for some services such as iScsiPrt) var virtualDeviceInstanceID = _installation.AllocateVirtualDeviceInstanceID(pnpDriverInf.ClassName); if (DeviceServices.Count > 0) { var deviceService = DeviceServices[0]; PreconfigureDeviceInstance(pnpDriverInf, "Root", pnpDriverInf.ClassName.ToUpper(), virtualDeviceInstanceID, deviceService); } } else // physical device { RegisterPhysicalDevice(pnpDriverInf); // GUI-Mode setup will scan all of the directories listed under "DevicePath" directories, // if it will find multiple matches, it will use the .inf file that has the best match. // Microsoft does not define exactly how matching drivers are ranked, observations show that: // 1. When both .inf have the exact same hardwareID, and one of the .inf is signed and the other is not, the signed .inf will qualify as the best match. // 2. When both .inf have the exact same hardwareID, and both of the .inf files are unsigned, the .inf with the most recent version / date will qualify as the best match. // 3. When both .inf have the exact same hardwareID, and both of the .inf files are unsigned, and both has the same version / date, the .inf from the first directory listed under "DevicePath" will qualify as the best match. // We have to disable the device drivers included in windows to qualify the newly integrated drivers as best match: PNPDriverGUIModeIntegrator.DisableInBoxDeviceDrivers(_installation.SetupDirectory, _installation.ArchitectureIdentifier, _installation.MinorOSVersion, _installation.ProductType, HardwareID); } // Network Device: // We want to make the NIC driver accessible to windows GUI mode setup, otherwise no 'Network Connection' will be installed and TCP/IP configuration // for the NIC will be deleted. (and as a result, the NIC would not have TCP/IP bound to it) // Devices in general: // Windows will clear all existing Enum and / or Control\Class entries of devices that have no matching driver available during GUI-mode setup // (it will be done near the very end of GUI-mode setup) // So we let Windows GUI-Mode install the device. // Note: the driver will be modified for boot start var guiModeIntegrator = new PNPDriverGUIModeIntegrator(DriverDirectory, _installation, HardwareID); guiModeIntegrator.Integrate(); }