/// <param name="sectionName"></param> /// <param name="relativeRoot"> /// The location where HKR entried will be stored, relative to 'SYSTEM\CurrentControlSet\' (or ControlSet001 for that matter) /// </param> /// <param name="pnpDriverInf"></param> private void ProcessAddRegSection(PNPDriverINFFile pnpDriverInf, string sectionName, string relativeRoot) { var section = pnpDriverInf.GetSection(sectionName); foreach (var line in section) { var values = INIFile.GetCommaSeparatedValues(line); var hiveName = values[0]; var subKeyName = INIFile.Unquote(values[1]); var valueName = INIFile.TryGetValue(values, 2); var valueType = INIFile.TryGetValue(values, 3); var valueDataUnparsed = string.Empty; if (values.Count > 3) { valueDataUnparsed = StringUtils.Join(values.GetRange(4, values.Count - 4), ","); } // byte-list is separated using commmas valueName = INIFile.Unquote(valueName); valueType = pnpDriverInf.ExpandToken(valueType); var valueTypeFlags = PNPDriverINFFile.ConvertFromIntStringOrHexString(valueType); var valueKind = PNPDriverINFFile.GetRegistryValueKind(valueTypeFlags); if (valueKind == RegistryValueKind.String) { valueDataUnparsed = pnpDriverInf.ExpandToken(valueDataUnparsed); } var valueData = HiveINIFile.ParseValueDataString(valueDataUnparsed, valueKind); if (hiveName == "HKR") { var cssKeyName = relativeRoot; if (subKeyName != string.Empty) { cssKeyName = cssKeyName + @"\" + subKeyName; } // Note that software key will stick from text-mode: SetCurrentControlSetRegistryKey(cssKeyName, valueName, valueKind, valueData); } else if (hiveName == "HKLM" && subKeyName.StartsWith(@"SYSTEM\CurrentControlSet\", StringComparison.InvariantCultureIgnoreCase)) { var cssKeyName = subKeyName.Substring(@"SYSTEM\CurrentControlSet\".Length); SetCurrentControlSetRegistryKey(cssKeyName, valueName, valueKind, valueData); } } }
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); } }