Exemplo n.º 1
0
        private void PreconfigureDeviceInstance(PNPDriverINFFile pnpDriverInf, ISystemRegistryHive systemRegistryHive, string enumerator, string deviceID, string deviceInstanceID, DeviceService deviceService)
        {
            string driver           = pnpDriverInf.ClassGUID.ToUpper() + @"\" + m_classInstanceID;
            string manufacturerName = pnpDriverInf.GetDeviceManufacturerName(this.HardwareID, m_installation.ArchitectureIdentifier, m_installation.MinorOSVersion, m_installation.ProductType);

            string 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(this.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 string[] { this.HardwareID });
            }

            // not necessary:
            systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "Mfg", RegistryValueKind.String, manufacturerName);
            systemRegistryHive.SetCurrentControlSetRegistryKey(hardwareKeyName, "Class", RegistryValueKind.String, pnpDriverInf.ClassName);
        }
Exemplo n.º 2
0
        public void IntegrateDriver()
        {
            PNPDriverINFFile pnpDriverInf;
            string           installSectionName = this.DriverDirectory.GetDeviceInstallSectionName(this.HardwareID, m_installation.ArchitectureIdentifier, m_installation.MinorOSVersion, m_installation.ProductType, out pnpDriverInf);

            if (installSectionName == String.Empty)
            {
                Console.WriteLine("Unable to locate InstallSectionName in INF file");
                Program.Exit();
            }

            m_classInstanceID = m_installation.SetupRegistryHive.AllocateClassInstanceID(pnpDriverInf.ClassGUID);

            ProcessInstallSection(pnpDriverInf, installSectionName, m_classInstanceID);
            ProcessInstallServicesSection(pnpDriverInf, installSectionName);
            // this.DeviceServices is now populated

            if (this.DeviceServices.Count == 0)
            {
                Console.WriteLine("Error: driver does not have an associated service, IntegrateDrv will not proceed.");
                Program.Exit();
            }

            PrepareToPreventTextModeDriverNameCollision(this.DeviceServices);

            foreach (DeviceService deviceService in this.DeviceServices)
            {
                InstructToLoadTextModeDeviceService(pnpDriverInf, deviceService);
                RegisterDeviceService(m_installation.SetupRegistryHive, pnpDriverInf, deviceService);
                RegisterDeviceService(m_installation.HiveSystemInf, pnpDriverInf, deviceService);
            }

            CopyDriverFiles(this.DeviceServices);

            // register the device:

            if (PNPDriverINFFile.IsRootDevice(this.HardwareID))
            {
                // installing virtual device: (this is critical for some services such as iScsiPrt)
                string virtualDeviceInstanceID = m_installation.AllocateVirtualDeviceInstanceID(pnpDriverInf.ClassName);
                if (this.DeviceServices.Count > 0)
                {
                    DeviceService deviceService = this.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(m_installation.SetupDirectory, m_installation.ArchitectureIdentifier, m_installation.MinorOSVersion, m_installation.ProductType, this.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
            PNPDriverGUIModeIntegrator guiModeIntegrator = new PNPDriverGUIModeIntegrator(this.DriverDirectory, m_installation, this.HardwareID);

            guiModeIntegrator.Integrate();
        }