Bios 数据读写

打印 上一主题 下一主题

主题 893|帖子 893|积分 2679

本文我们介绍针对Bios怎样读取、写入数据,好比最常见的SN读取以及烧录
WMI查询

先看看WMI方式,读取BIOS信息
WMI-Win32_BIOS,可以查看Bios版本、制造商以及Bios Sn等:
  1. 1             var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
  2. 2             Console.WriteLine("Win32_BIOS 获取bios信息:");
  3. 3             foreach (var baseObject in searcher.Get())
  4. 4             {
  5. 5                 Console.WriteLine("Manufacturer: " + baseObject["Manufacturer"]);
  6. 6                 Console.WriteLine("Version: " + baseObject["Version"]);
  7. 7                 Console.WriteLine("SMBIOS BIOS Version: " + baseObject["SMBIOSBIOSVersion"]);
  8. 8                 Console.WriteLine("Name: " + baseObject["Name"]);
  9. 9                 Console.WriteLine("Release Date: " + baseObject["ReleaseDate"]);
  10. 10                 Console.WriteLine("Serial Number: " + baseObject["SerialNumber"]);
  11. 11                 Console.WriteLine("Status: " + baseObject["Status"]);
  12. 12                 Console.WriteLine("Caption: " + baseObject["Caption"]);
  13. 13                 Console.WriteLine("Build Number: " + baseObject["BuildNumber"]);
  14. 14                 Console.WriteLine("Code Set: " + baseObject["CodeSet"]);
  15. 15                 Console.WriteLine("Current Language: " + baseObject["CurrentLanguage"]);
  16. 16                 Console.WriteLine("Description: " + baseObject["Description"]);
  17. 17                 Console.WriteLine("Embedded Controller Major Version: " + baseObject["EmbeddedControllerMajorVersion"]);
  18. 18                 Console.WriteLine("Embedded Controller Minor Version: " + baseObject["EmbeddedControllerMinorVersion"]);
  19. 19                 Console.WriteLine("Identification Code: " + baseObject["IdentificationCode"]);
  20. 20                 Console.WriteLine("Installable Languages: " + baseObject["InstallableLanguages"]);
  21. 21                 Console.WriteLine("Install Date: " + baseObject["InstallDate"]);
  22. 22                 Console.WriteLine("Language Edition: " + baseObject["LanguageEdition"]);
  23. 23                 Console.WriteLine("List Of Languages: " + baseObject["ListOfLanguages"]);
  24. 24                 Console.WriteLine("Other Target OS: " + baseObject["OtherTargetOS"]);
  25. 25                 Console.WriteLine("Primary BIOS: " + baseObject["PrimaryBIOS"]);
  26. 26                 Console.WriteLine("System BIOS Major Version: " + baseObject["SystemBiosMajorVersion"]);
  27. 27                 Console.WriteLine("System BIOS Minor Version: " + baseObject["SystemBiosMinorVersion"]);
  28. 28                 Console.WriteLine("Target Operating System: " + baseObject["TargetOperatingSystem"]);
  29. 29                 Console.WriteLine("-----------------------------------");
  30. 30             }
  31. 31             searcher.Dispose();
复制代码
这是个人电脑获取结果:

电脑-系统信息中的Bios版本信息,是以上面Bios制造商+Bios版本+发布日期拼接显示:

WMI-Win32_BaseBoard,可以获取主板SN以及主板制造商:
  1. 1             var searcher1 = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
  2. 2             Console.WriteLine("Win32_BaseBoard获取bios信息:");
  3. 3             foreach (var baseObject in searcher1.Get())
  4. 4             {
  5. 5                 Console.WriteLine("Board Serial Number: " + baseObject["SerialNumber"]);
  6. 6                 Console.WriteLine("Manufacturer: " + baseObject["Manufacturer"]);
  7. 7                 Console.WriteLine("Product Name: " + baseObject["Product"]);
  8. 8                 Console.WriteLine("Version: " + baseObject["Version"]);
  9. 9             }
  10. 10             searcher1.Dispose();
复制代码
个人电脑获取结果:

Amide读写

获取Bios信息也可以使用AmideWin工具,同时此工具也可以用于数据写入。通过该工具可以轻松地自定义系统UUID、调解DMI信息,从而满足各种特定的系统需求好比指定BIOS位置的数据。其技能实现主要依赖于对BIOS固件的底层访问和修改
读取指定位置数据:
[code] 1     private static string ReadBiosData(string command) 2     { 3         var amiExePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AmiBios", "AMIDEWINx64.EXE"); 4         var startInfo = new ProcessStartInfo 5         { 6             FileName = $"\"{amiExePath}\"", 7             Arguments = command, 8             Verb = "runas", 9             UseShellExecute = false,10             RedirectStandardError = true,11             RedirectStandardInput = true,12             RedirectStandardOutput = true,13             CreateNoWindow = true,14             WindowStyle = ProcessWindowStyle.Hidden15         };16         using var process = Process.Start(startInfo);17         if (process == null) return "";18         process.WaitForExit();19         string output = process.StandardOutput.ReadToEnd();20 21         if (string.IsNullOrWhiteSpace(output)) return "读取输出结果为空";22         string[] inputs = output.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);23         string targetOutput = inputs.FirstOrDefault(p => p.Contains(command));24         if (targetOutput == null) return $"输出数据:{output}未找到指定Key[{command}]的目标输出";25         string value = ExtractMiddleContent(targetOutput, "\"", "\"");26         return value;27     }28     private static string ExtractMiddleContent(string source, string begin, string end)29     {30         var rg = new Regex("(?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

王海鱼

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表