コード例 #1
0
        private void ProcessEventLogInstallSection(PNPDriverINFFile pnpDriverInf, string sectionName, string eventLogType,
                                                   string eventName)
        {
            var installSection = pnpDriverInf.GetSection(sectionName);

            var relativeRoot = @"Services\EventLog\" + eventLogType + @"\" + eventName;

            foreach (var line in installSection)
            {
                var keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "AddReg":
                {
                    foreach (var registrySectionName in keyAndValues.Value)
                    {
                        ProcessAddRegSection(pnpDriverInf, registrySectionName, relativeRoot);
                    }
                    break;
                }
                }
            }
        }
コード例 #2
0
        protected void ProcessInstallServicesSection(PNPDriverINFFile pnpDriverInf, string installSectionName)
        {
            var installServicesSection = pnpDriverInf.GetInstallServicesSection(installSectionName, _architectureIdentifier,
                                                                                _minorOSVersion);

            foreach (var line in installServicesSection)
            {
                var keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "AddService":
                {
                    var serviceName            = keyAndValues.Value[0];
                    var serviceInstallSection  = keyAndValues.Value[2];
                    var eventLogInstallSection = INIFile.TryGetValue(keyAndValues.Value, 3);
                    var eventLogType           = INIFile.TryGetValue(keyAndValues.Value, 4);
                    var eventName = INIFile.TryGetValue(keyAndValues.Value, 5);
                    ProcessServiceInstallSection(pnpDriverInf, serviceInstallSection, serviceName);
                    if (eventLogInstallSection != string.Empty)
                    {
                        // http://msdn.microsoft.com/en-us/library/ff546326%28v=vs.85%29.aspx
                        if (eventLogType == string.Empty)
                        {
                            eventLogType = "System";
                        }
                        if (eventName == string.Empty)
                        {
                            eventName = serviceName;
                        }
                        ProcessEventLogInstallSection(pnpDriverInf, eventLogInstallSection, eventLogType, eventName);
                    }
                    break;
                }
                }
            }
        }
コード例 #3
0
        // DDInstall Section in a Network INF File:
        // http://msdn.microsoft.com/en-us/library/ff546329%28VS.85%29.aspx
        protected void ProcessInstallSection(PNPDriverINFFile pnpDriverInf, string installSectionName, string classInstanceID)
        {
            var installSection = pnpDriverInf.GetInstallSection(installSectionName, _architectureIdentifier, _minorOSVersion);

            var softwareKeyName = @"Control\Class\" + pnpDriverInf.ClassGUID + @"\" + classInstanceID;

            foreach (var line in installSection)
            {
                var keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "AddReg":
                {
                    foreach (var registrySectionName in keyAndValues.Value)
                    {
                        ProcessAddRegSection(pnpDriverInf, registrySectionName, softwareKeyName);
                    }
                    break;
                }

                case "CopyFiles":
                {
                    if (keyAndValues.Value[0].StartsWith("@"))
                    {
                        ProcessCopyFileDirective(pnpDriverInf, keyAndValues.Value[0].Substring(1));
                    }
                    else
                    {
                        foreach (var copyFilesSectionName in keyAndValues.Value)
                        {
                            ProcessCopyFilesSection(pnpDriverInf, copyFilesSectionName);
                        }
                    }
                    break;
                }

                case "BusType":
                {
                    if (pnpDriverInf.IsNetworkAdapter)
                    {
                        // Some NICs (AMD PCNet) won't start if BusType is not set (CM_PROB_FAILED_START)
                        var busType = Convert.ToInt32(keyAndValues.Value[0]);

                        SetCurrentControlSetRegistryKey(softwareKeyName, "BusType", RegistryValueKind.String, busType.ToString(CultureInfo.InvariantCulture));
                    }
                    break;
                }

                case "Characteristics":
                {
                    if (pnpDriverInf.IsNetworkAdapter)
                    {
                        // No evidence so far that the presence of this value is critical, but it's a good practice to add it
                        var characteristics = PNPDriverINFFile.ConvertFromIntStringOrHexString(keyAndValues.Value[0]);

                        SetCurrentControlSetRegistryKey(softwareKeyName, "Characteristics", RegistryValueKind.DWord, characteristics);
                    }
                    break;
                }
                }
            }
        }
コード例 #4
0
        private void ProcessServiceInstallSection(PNPDriverINFFile pnpDriverInf, string sectionName, string serviceName)
        {
            Console.WriteLine("Registering service '" + serviceName + "'");
            var serviceInstallSection = pnpDriverInf.GetSection(sectionName);

            var displayName        = string.Empty;
            var serviceBinary      = string.Empty;
            var serviceTypeString  = string.Empty;
            var errorControlString = string.Empty;
            var loadOrderGroup     = string.Empty;

            //string guiModeRelativeRoot = @"Services\" + serviceName;
            foreach (var line in serviceInstallSection)
            {
                var keyAndValues = INIFile.GetKeyAndValues(line);
                switch (keyAndValues.Key)
                {
                case "AddReg":
                {
                    // http://msdn.microsoft.com/en-us/library/ff546326%28v=vs.85%29.aspx
                    // AddReg will always come after ServiceBinaryServiceBinary

                    var relativeRoot = @"Services\" + serviceName;

                    foreach (var registrySectionName in keyAndValues.Value)
                    {
                        ProcessAddRegSection(pnpDriverInf, registrySectionName, relativeRoot);
                    }
                    break;
                }

                case "DisplayName":
                {
                    displayName = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;
                }

                case "ServiceBinary":
                {
                    serviceBinary = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;
                }

                case "ServiceType":
                {
                    serviceTypeString = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;
                }

                case "ErrorControl":
                {
                    errorControlString = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;
                }

                case "LoadOrderGroup":
                {
                    loadOrderGroup = INIFile.TryGetValue(keyAndValues.Value, 0);
                    break;
                }
                }
            }

            displayName = pnpDriverInf.ExpandToken(displayName);
            displayName = INIFile.Unquote(displayName);

            var fileName  = serviceBinary.Replace(@"%12%\", string.Empty);
            var imagePath = PNPDriverINFFile.ExpandDirID(serviceBinary);

            var serviceType  = PNPDriverINFFile.ConvertFromIntStringOrHexString(serviceTypeString);
            var errorControl = PNPDriverINFFile.ConvertFromIntStringOrHexString(errorControlString);

            var deviceDescription = pnpDriverInf.GetDeviceDescription(_hardwareID, _architectureIdentifier, _minorOSVersion,
                                                                      _productType);

            BaseDeviceService deviceService;

            if (pnpDriverInf.IsNetworkAdapter)
            {
                // this is a nic, we are binding TCP/IP to it
                // we need a unique NetCfgInstanceID that will be used with Tcpip service and the nic's class
                var netCfgInstanceID = "{" + Guid.NewGuid().ToString().ToUpper() + "}";
                deviceService = new NetworkDeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType,
                                                         errorControl, fileName, imagePath, netCfgInstanceID);
                _deviceServices.Add(deviceService);
            }
            else
            {
                deviceService = new BaseDeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType,
                                                      errorControl, fileName, imagePath);
                _deviceServices.Add(deviceService);
            }
        }