qidao123.com技术社区-IT企服评测·应用市场
标题:
Bios 数据读写
[打印本页]
作者:
王海鱼
时间:
2024-12-24 10:56
标题:
Bios 数据读写
本文我们介绍针对Bios怎样读取、写入数据,好比最常见的SN读取以及烧录
WMI查询
先看看WMI方式,读取BIOS信息
WMI-Win32_BIOS,可以查看Bios版本、制造商以及Bios Sn等:
1 var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_BIOS");
2 Console.WriteLine("Win32_BIOS 获取bios信息:");
3 foreach (var baseObject in searcher.Get())
4 {
5 Console.WriteLine("Manufacturer: " + baseObject["Manufacturer"]);
6 Console.WriteLine("Version: " + baseObject["Version"]);
7 Console.WriteLine("SMBIOS BIOS Version: " + baseObject["SMBIOSBIOSVersion"]);
8 Console.WriteLine("Name: " + baseObject["Name"]);
9 Console.WriteLine("Release Date: " + baseObject["ReleaseDate"]);
10 Console.WriteLine("Serial Number: " + baseObject["SerialNumber"]);
11 Console.WriteLine("Status: " + baseObject["Status"]);
12 Console.WriteLine("Caption: " + baseObject["Caption"]);
13 Console.WriteLine("Build Number: " + baseObject["BuildNumber"]);
14 Console.WriteLine("Code Set: " + baseObject["CodeSet"]);
15 Console.WriteLine("Current Language: " + baseObject["CurrentLanguage"]);
16 Console.WriteLine("Description: " + baseObject["Description"]);
17 Console.WriteLine("Embedded Controller Major Version: " + baseObject["EmbeddedControllerMajorVersion"]);
18 Console.WriteLine("Embedded Controller Minor Version: " + baseObject["EmbeddedControllerMinorVersion"]);
19 Console.WriteLine("Identification Code: " + baseObject["IdentificationCode"]);
20 Console.WriteLine("Installable Languages: " + baseObject["InstallableLanguages"]);
21 Console.WriteLine("Install Date: " + baseObject["InstallDate"]);
22 Console.WriteLine("Language Edition: " + baseObject["LanguageEdition"]);
23 Console.WriteLine("List Of Languages: " + baseObject["ListOfLanguages"]);
24 Console.WriteLine("Other Target OS: " + baseObject["OtherTargetOS"]);
25 Console.WriteLine("Primary BIOS: " + baseObject["PrimaryBIOS"]);
26 Console.WriteLine("System BIOS Major Version: " + baseObject["SystemBiosMajorVersion"]);
27 Console.WriteLine("System BIOS Minor Version: " + baseObject["SystemBiosMinorVersion"]);
28 Console.WriteLine("Target Operating System: " + baseObject["TargetOperatingSystem"]);
29 Console.WriteLine("-----------------------------------");
30 }
31 searcher.Dispose();
复制代码
这是个人电脑获取结果:
电脑-系统信息中的Bios版本信息,是以上面Bios制造商+Bios版本+发布日期拼接显示:
WMI-Win32_BaseBoard,可以获取主板SN以及主板制造商:
1 var searcher1 = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
2 Console.WriteLine("Win32_BaseBoard获取bios信息:");
3 foreach (var baseObject in searcher1.Get())
4 {
5 Console.WriteLine("Board Serial Number: " + baseObject["SerialNumber"]);
6 Console.WriteLine("Manufacturer: " + baseObject["Manufacturer"]);
7 Console.WriteLine("Product Name: " + baseObject["Product"]);
8 Console.WriteLine("Version: " + baseObject["Version"]);
9 }
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("(?
欢迎光临 qidao123.com技术社区-IT企服评测·应用市场 (https://dis.qidao123.com/)
Powered by Discuz! X3.4