protected void ProcessCoInstallersSection(PNPDriverINFFile pnpDriverInf, string installSectionName) { string matchingInstallSectionName = pnpDriverInf.GetMatchingInstallSectionName(installSectionName, m_architectureIdentifier, m_minorOSVersion); if (matchingInstallSectionName == String.Empty) { return; } string matchingCoInstallersSectionName = matchingInstallSectionName + ".CoInstallers"; List <string> coinstallersSection = pnpDriverInf.GetSection(matchingCoInstallersSectionName); foreach (string line in coinstallersSection) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); switch (keyAndValues.Key) { case "CopyFiles": if (keyAndValues.Value[0].StartsWith("@")) { ProcessCopyFileDirective(pnpDriverInf, keyAndValues.Value[0].Substring(1)); } else { foreach (string copyFilesSectionName in keyAndValues.Value) { ProcessCopyFilesSection(pnpDriverInf, copyFilesSectionName); } } break; default: break; } } }
// 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) { List <string> installSection = pnpDriverInf.GetInstallSection(installSectionName, m_architectureIdentifier, m_minorOSVersion); string softwareKeyName = @"Control\Class\" + pnpDriverInf.ClassGUID + @"\" + classInstanceID; foreach (string line in installSection) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); switch (keyAndValues.Key) { case "AddReg": foreach (string 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 (string 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) int busType = Convert.ToInt32(keyAndValues.Value[0]); SetCurrentControlSetRegistryKey(softwareKeyName, "BusType", RegistryValueKind.String, busType.ToString()); } 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 int characteristics = PNPDriverINFFile.ConvertFromIntStringOrHexString(keyAndValues.Value[0]); SetCurrentControlSetRegistryKey(softwareKeyName, "Characteristics", RegistryValueKind.DWord, characteristics); } break; default: break; } } }
public string GetTokenValue(string token) { List <string> strings = GetSection("Strings"); foreach (string line in strings) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); if (keyAndValues.Key.Equals(token, StringComparison.InvariantCultureIgnoreCase)) { return(keyAndValues.Value[0]); } } throw new KeyNotFoundException(String.Format("Inf file '{0}' is not valid, token '{1}' was not found!", this.FileName, token)); }
private bool IsDirectoryIDTaken(string directoryID) { List <string> section = GetSection("Directories"); foreach (string line in section) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); if (keyAndValues.Key.Equals(directoryID)) { return(true); } } return(false); }
public string GetDirectoryOfDisk(string diskName) { List <string> section = GetSection("Disks"); foreach (string line in section) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); if (keyAndValues.Key == diskName) { string directory = keyAndValues.Value[2]; return(directory); } } return(String.Empty); }
public List <string> ListManufacturerIDs() { List <string> manufacturerIDs = new List <string>(); List <string> manufacturers = GetSection("Manufacturer"); foreach (string manufacturer in manufacturers) { KeyValuePair <string, List <string> > manufacturerKeyAndValues = INIFile.GetKeyAndValues(manufacturer); if (manufacturerKeyAndValues.Value.Count >= 1) { string manufacturerID = manufacturerKeyAndValues.Value[0]; manufacturerIDs.Add(manufacturerID); } } return(manufacturerIDs); }
public void SetServiceToBootStart(string installSectionName, string architectureIdentifier, int minorOSVersion, bool updateConsole) { List <string> installServicesSection = GetInstallServicesSection(installSectionName, architectureIdentifier, minorOSVersion); foreach (string line in installServicesSection) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); if (keyAndValues.Key == "AddService") { string serviceName = keyAndValues.Value[0]; string serviceInstallSection = keyAndValues.Value[2]; this.SetServiceToBootStart(serviceInstallSection); if (updateConsole) { Console.WriteLine("Service '" + serviceName + "' has been set to boot start"); } } } }
public string GetDeviceInstallSectionName(string hardwareIDToFind, string architectureIdentifier, int minorOSVersion, int productType) { List <string> manufacturerIDs = ListManufacturerIDs(); foreach (string manufacturerID in manufacturerIDs) { List <string> models = GetModelsSection(manufacturerID, architectureIdentifier, minorOSVersion, productType); foreach (string model in models) { KeyValuePair <string, List <string> > modelKeyAndValues = INIFile.GetKeyAndValues(model); if (modelKeyAndValues.Value.Count >= 2) { string hardwareID = modelKeyAndValues.Value[1]; if (String.Equals(hardwareID, hardwareIDToFind, StringComparison.InvariantCultureIgnoreCase)) { string installSectionName = modelKeyAndValues.Value[0]; return(installSectionName); } } } } return(String.Empty); }
private void ProcessEventLogInstallSection(PNPDriverINFFile pnpDriverInf, string sectionName, string eventLogType, string eventName) { List <string> installSection = pnpDriverInf.GetSection(sectionName); string relativeRoot = @"Services\EventLog\" + eventLogType + @"\" + eventName; foreach (string line in installSection) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); switch (keyAndValues.Key) { case "AddReg": foreach (string registrySectionName in keyAndValues.Value) { ProcessAddRegSection(pnpDriverInf, registrySectionName, relativeRoot); } break; default: break; } } }
public bool DisableMatchingHardwareID(string hardwareIDToDisable, string architectureIdentifier, int minorOSVersion, int productType) { bool found = false; string genericHardwareID = GetGenericHardwareID(hardwareIDToDisable); List <string> manufacturerIDs = ListManufacturerIDs(); foreach (string manufacturerID in manufacturerIDs) { string modelsSectionName = GetMatchingModelsSectionName(manufacturerID, architectureIdentifier, minorOSVersion, productType); if (modelsSectionName == String.Empty) { continue; } List <string> models = GetSection(modelsSectionName); foreach (string model in models) { KeyValuePair <string, List <string> > modelKeyAndValues = INIFile.GetKeyAndValues(model); if (modelKeyAndValues.Value.Count >= 2) { string hardwareID = modelKeyAndValues.Value[1]; if (hardwareID.StartsWith(genericHardwareID, StringComparison.InvariantCultureIgnoreCase)) { int lineIndex = GetLineIndex(modelsSectionName, model); UpdateLine(lineIndex, ";" + model); found = true; } } } } return(found); }
protected void ProcessInstallServicesSection(PNPDriverINFFile pnpDriverInf, string installSectionName) { List <string> installServicesSection = pnpDriverInf.GetInstallServicesSection(installSectionName, m_architectureIdentifier, m_minorOSVersion); foreach (string line in installServicesSection) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); switch (keyAndValues.Key) { case "AddService": string serviceName = keyAndValues.Value[0]; string serviceInstallSection = keyAndValues.Value[2]; string eventLogInstallSection = INIFile.TryGetValue(keyAndValues.Value, 3); string eventLogType = INIFile.TryGetValue(keyAndValues.Value, 4); string 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; default: break; } } }
// update txtsetup.sif and dotnet.inf private void UpdateTextSetupInformationFileAndCopyFiles(string deviceID) { // Files.HwComponent.ID Section TextModeDriverSetupINIFile driverINI = m_driverDirectory.TextModeDriverSetupINI; List <string> section = driverINI.GetDriverFilesSection(deviceID); string serviceName = String.Empty; List <string> driverKeys = new List <string>(); string sourceDirectoryInMediaRootForm = m_installation.GetSourceDriverDirectoryInMediaRootForm(deviceID); int sourceDiskID = m_installation.TextSetupInf.AllocateSourceDiskID(m_installation.ArchitectureIdentifier, sourceDirectoryInMediaRootForm); string destinationWinntDirectory = m_installation.GetDriverDestinationWinntDirectory(m_deviceID); int destinationWinntDirectoryID = m_installation.TextSetupInf.AllocateWinntDirectoryID(destinationWinntDirectory); foreach (string line in section) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); string fileType = keyAndValues.Key; string directory = driverINI.GetDirectoryOfDisk(keyAndValues.Value[0]); string fileName = keyAndValues.Value[1]; string sourceFilePath = m_driverDirectory.Path + "." + directory + @"\" + fileName; bool isDriver = keyAndValues.Key.Equals("driver", StringComparison.InvariantCultureIgnoreCase); m_installation.CopyFileToSetupDriverDirectory(sourceFilePath, deviceID + @"\", fileName); if (isDriver) { m_installation.CopyDriverToSetupRootDirectory(sourceFilePath, fileName); if (m_installation.IsTargetContainsTemporaryInstallation) { m_installation.CopyFileFromSetupDirectoryToBootDirectory(fileName); } } m_installation.TextSetupInf.SetSourceDisksFileEntry(m_installation.ArchitectureIdentifier, sourceDiskID, destinationWinntDirectoryID, fileName, FileCopyDisposition.AlwaysCopy); if (isDriver) { // http://msdn.microsoft.com/en-us/library/ff544919%28v=VS.85%29.aspx // unlike what one may understand from the reading specs, this value is *only* used to form [Config.DriverKey] section name, // and definitely NOT to determine the service subkey name under CurrentControlSet\Services. (which is determined by the service file name without a .sys extension) string driverKey = keyAndValues.Value[2]; // http://support.microsoft.com/kb/885756 // according to this, only the first driver entry should be processed. // http://app.nidc.kr/dirver/IBM_ServerGuide_v7.4.17/sguide/w3x64drv/$oem$/$1/drv/dds/txtsetup.oem // however, this sample and my experience suggest that files / registry entries from a second driver entry will be copied / registered, // (both under the same Services\serviceName key), so we'll immitate that. driverKeys.Add(driverKey); if (serviceName == String.Empty) { // Some txtsetup.oem drivers are without HardwareID entries, // but we already know that the service is specified by the file name of its executable image without a .sys extension, // so we should use that. serviceName = TextSetupINFFile.GetServiceName(fileName); } // We should use FileCopyDisposition.DoNotCopy, because InstructToLoadSCSIDriver will already copy the device driver. m_installation.TextSetupInf.SetSourceDisksFileDriverEntry(m_installation.ArchitectureIdentifier, fileName, FileCopyDisposition.DoNotCopy); m_installation.TextSetupInf.SetFileFlagsEntryForDriver(fileName); string deviceName = driverINI.GetDeviceName(deviceID); m_installation.TextSetupInf.InstructToLoadSCSIDriver(fileName, deviceName); } // add file to the list of files to be copied to local source directory if (!m_installation.IsTargetContainsTemporaryInstallation) { m_installation.DosNetInf.InstructSetupToCopyFileFromSetupDirectoryToLocalSourceDriverDirectory(sourceDirectoryInMediaRootForm, fileName); if (isDriver) { m_installation.DosNetInf.InstructSetupToCopyFileFromSetupDirectoryToBootDirectory(fileName); } } } section = driverINI.GetHardwareIdsSection(deviceID); foreach (string line in section) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); string hardwareID = keyAndValues.Value[0]; // http://msdn.microsoft.com/en-us/library/ff546129%28v=VS.85%29.aspx // The service is specified by the file name of its executable image without a .sys extension // it is incomprehensible that this line will change the value of serviceName, because we already set serviceName to the service file name without a .sys extension serviceName = INIFile.Unquote(keyAndValues.Value[1]); hardwareID = INIFile.Unquote(hardwareID); m_installation.TextSetupInf.AddDeviceToCriticalDeviceDatabase(hardwareID, serviceName); } foreach (string driverKey in driverKeys) { section = driverINI.GetConfigSection(driverKey); foreach (string line in section) { KeyValuePair <string, List <string> > keyAndValues = INIFile.GetKeyAndValues(line); string subKeyNameQuoted = keyAndValues.Value[0]; string valueName = keyAndValues.Value[1]; string valueType = keyAndValues.Value[2]; string valueDataUnparsed = keyAndValues.Value[3]; RegistryValueKind valueKind = TextModeDriverSetupINIFile.GetRegistryValueKind(valueType); object valueData = HiveINIFile.ParseValueDataString(valueDataUnparsed, valueKind); string subKeyName = INIFile.Unquote(subKeyNameQuoted); m_installation.HiveSystemInf.SetServiceRegistryKey(serviceName, subKeyName, valueName, valueKind, valueData); m_installation.SetupRegistryHive.SetServiceRegistryKey(serviceName, subKeyName, valueName, valueKind, valueData); } } }
private void ProcessServiceInstallSection(PNPDriverINFFile pnpDriverInf, string sectionName, string serviceName) { Console.WriteLine("Registering service '" + serviceName + "'"); List <string> serviceInstallSection = pnpDriverInf.GetSection(sectionName); string displayName = String.Empty; string serviceBinary = String.Empty; string serviceTypeString = String.Empty; string errorControlString = String.Empty; string loadOrderGroup = String.Empty; //string guiModeRelativeRoot = @"Services\" + serviceName; foreach (string line in serviceInstallSection) { KeyValuePair <string, List <string> > 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 string relativeRoot = @"Services\" + serviceName; foreach (string 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; default: break; } } displayName = pnpDriverInf.ExpandToken(displayName); displayName = INIFile.Unquote(displayName); string fileName = serviceBinary.Replace(@"%12%\", String.Empty); string imagePath = pnpDriverInf.ExpandDirID(serviceBinary); int serviceType = PNPDriverINFFile.ConvertFromIntStringOrHexString(serviceTypeString); int errorControl = PNPDriverINFFile.ConvertFromIntStringOrHexString(errorControlString); string deviceDescription = pnpDriverInf.GetDeviceDescription(m_hardwareID, m_architectureIdentifier, m_minorOSVersion, m_productType); DeviceService 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 string netCfgInstanceID = "{" + Guid.NewGuid().ToString().ToUpper() + "}"; deviceService = new NetworkDeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType, errorControl, fileName, imagePath, netCfgInstanceID); m_deviceServices.Add(deviceService); } else { deviceService = new DeviceService(deviceDescription, serviceName, displayName, loadOrderGroup, serviceType, errorControl, fileName, imagePath); m_deviceServices.Add(deviceService); } }