|
- #include <iostream>
- #include <windows.h>
- #include <string>
- int main() {
- DWORD bufferSize = 0;
- BYTE* buffer = nullptr;
- DWORD dataType = 0;
- std::string biosInfo;
- // 获取缓冲区大小
- if (GetSystemFirmwareTable(FirmwareTableProviderSignature, FirmwareTableID, 0, &bufferSize) != ERROR_INSUFFICIENT_BUFFER) {
- std::cerr << "无法获取缓冲区大小" << std::endl;
- return 1;
- }
- // 分配缓冲区
- buffer = new BYTE[bufferSize];
- // 获取BIOS信息
- if (GetSystemFirmwareTable(FirmwareTableProviderSignature, FirmwareTableID, buffer, &bufferSize) == ERROR_SUCCESS) {
- // 解析BIOS信息
- for (DWORD i = 0; i < bufferSize; i++) {
- switch (dataType) {
- case 0: // 制造商
- if (buffer[i] == 0) {
- dataType = 1;
- } else {
- biosInfo += static_cast<char>(buffer[i]);
- }
- break;
- case 1: // 序列号
- if (buffer[i] == 0) {
- dataType = 2;
- } else {
- biosInfo += static_cast<char>(buffer[i]);
- }
- break;
- case 2: // 发布日期
- if (buffer[i] == 0) {
- dataType = 3;
- } else {
- biosInfo += static_cast<char>(buffer[i]);
- }
- break;
- case 3: // 版本
- if (buffer[i] == 0) {
- dataType = 4;
- } else {
- biosInfo += static_cast<char>(buffer[i]);
- }
- break;
- }
- }
- } else {
- std::cerr << "无法获取BIOS信息" << std::endl;
- delete[] buffer;
- return 1;
- }
- // 输出BIOS信息
- std::cout << "制造商: " << biosInfo.substr(0, biosInfo.find('\0')) << std::endl;
- std::cout << "序列号: " << biosInfo.substr(biosInfo.find('\0') + 1, biosInfo.find('\0', biosInfo.find('\0') + 1)) << std::endl;
- std::cout << "发布日期: " << biosInfo.substr(biosInfo.find('\0', biosInfo.find('\0') + 1) + 1, biosInfo.find('\0', biosInfo.find('\0', biosInfo.find('\0') + 1) + 1)) << std::endl;
- std::cout << "版本: " << biosInfo.substr(biosInfo.find('\0', biosInfo.find('\0', biosInfo.find('\0') + 1) + 1) + 1) << std::endl;
- // 释放缓冲区
- delete[] buffer;
- return 0;
- }
复制代码 |
|