使用Windows自带的函数完成:GetSystemFirmwareTable()
#include <Windows.h>
#include <stdio.h>
#include <string.h>
#include <string>typedef struct _dmi_header
{BYTE type;BYTE length;WORD handle;
}dmi_header;typedef struct _RawSMBIOSData
{BYTE    Used20CallingMethod;BYTE    SMBIOSMajorVersion;BYTE    SMBIOSMinorVersion;BYTE    DmiRevision;DWORD   Length;BYTE    SMBIOSTableData[];
}RawSMBIOSData;const char *dmi_chassis_type(BYTE code)
{/* 7.4.1 */static const char *type[] = {"Other", /* 0x01 */"Unknown","Desktop","Low Profile Desktop","Pizza Box","Mini Tower","Tower","Portable","Laptop","Notebook","Hand Held","Docking Station","All In One","Sub Notebook","Space-saving","Lunch Box","Main Server Chassis", /* CIM_Chassis.ChassisPackageType says "Main System Chassis" */"Expansion Chassis","Sub Chassis","Bus Expansion Chassis","Peripheral Chassis","RAID Chassis","Rack Mount Chassis","Sealed-case PC","Multi-system","CompactPCI","AdvancedTCA","Blade","Blade Enclosing" /* 0x1D */};code &= 0x7F; /* bits 6:0 are chassis type, 7th bit is the lock bit */if (code >= 0x01 && code <= 0x1D)return type[code - 0x01];return "unknown";
}void dmi_system_uuid(const BYTE *p, short ver,std::string &uuid)
{int only0xFF = 1, only0x00 = 1;int i;for (i = 0; i < 16 && (only0x00 || only0xFF); i++){if (p[i] != 0x00) only0x00 = 0;if (p[i] != 0xFF) only0xFF = 0;}if (only0xFF){printf("Not Present");return;}if (only0x00){printf("Not Settable");return;}/** As of version 2.6 of the SMBIOS specification, the first 3* fields of the UUID are supposed to be encoded on little-endian.* The specification says that this is the defacto standard,* however I've seen systems following RFC 4122 instead and use* network byte order, so I am reluctant to apply the byte-swapping* for older versions.*/char ch[256];memset(ch,0,sizeof(ch));if (ver >= 0x0206)sprintf(ch,"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",p[3], p[2], p[1], p[0], p[5], p[4], p[7], p[6],p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);elsesprintf(ch,"%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7],p[8], p[9], p[10], p[11], p[12], p[13], p[14], p[15]);printf("%s\n",ch);uuid = std::string(ch);
}const char *dmi_string(const dmi_header *dm, BYTE s)
{char *bp = (char *)dm;size_t i, len;if (s == 0)return "Not Specified";bp += dm->length;while (s > 1 && *bp){bp += strlen(bp);bp++;s--;}if (!*bp)return "BAD_INDEX";/* ASCII filtering */len = strlen(bp);for (i = 0; i < len; i++)if (bp[i] < 32 || bp[i] == 127)bp[i] = '.';return bp;
}int GetSystemUUID(std::string &uuid)
{int ret = 0;RawSMBIOSData *Smbios;dmi_header *h = NULL;int flag = 1;ret = GetSystemFirmwareTable('RSMB', 0, 0, 0);if (!ret){printf("Function failed!\n");return 1;}//printf("get buffer size is %d\n", ret);DWORD bufsize = ret;char *buf = new char[bufsize];memset(buf,0,bufsize);ret = GetSystemFirmwareTable('RSMB', 0, buf, bufsize);if (!ret){printf("Function failed!\n");delete []buf;return 1;}Smbios = (RawSMBIOSData *)buf;BYTE *p = Smbios->SMBIOSTableData;if (Smbios->Length != bufsize -8 ){printf("Smbios length error\n");delete []buf;return 1;}for(int i =0; i<Smbios->Length; i++){h = (dmi_header *)p;if (h->type == 0 && flag) {printf("\nType %02d - [BIOS]\n", h->type);printf("\tBIOS Vendor : %s\n", dmi_string(h, p[0x4]));printf("\tBIOS Version: %s\n", dmi_string(h, p[0x5]));printf("\tRelease Date: %s\n", dmi_string(h, p[0x8]));if(p[0x16]!=0xff && p[0x17]!=0xff)printf("\tEC version: %d.%d\n", p[0x16], p[0x17]);flag = 0;}else if (h->type == 1) {printf("\nType %02d - [System Information]\n", h->type);printf("\tManufacturer: %s\n", dmi_string(h, p[0x4]));printf("\tProduct Name: %s\n", dmi_string(h, p[0x5]));printf("\tVersion: %s\n", dmi_string(h, p[0x6]));printf("\tSerial Number: %s\n", dmi_string(h, p[0x7]));printf("\tUUID: "); dmi_system_uuid(p+0x8, Smbios->SMBIOSMajorVersion*0x100+Smbios->SMBIOSMinorVersion,uuid);printf("\tSKU Number: %s\n", dmi_string(h, p[0x19]));printf("\tFamily: %s\n", dmi_string(h, p[0x1a]));}else if (h->type == 2) {printf("\nType %02d - [System Information]\n", h->type);printf("\tManufacturer: %s\n", dmi_string(h, p[0x4]));printf("\tProduct: %s\n", dmi_string(h, p[0x5]));printf("\tVersion: %s\n", dmi_string(h, p[0x6]));printf("\tSerial Number: %s\n", dmi_string(h, p[0x7]));printf("\tAsset Tag: %s\n", dmi_string(h, p[0x8]));printf("\tLocation in Chassis: %s\n", dmi_string(h, p[0x0a]));}else if (h->type == 3) {printf("\nType %02d - [System Enclosure or Chassis]\n", h->type);printf("\tManufacturer: %s\n", dmi_string(h, p[0x04]));printf("\tType: %s\n", dmi_chassis_type(p[0x05]));printf("\tVersion: %s\n", dmi_string(h, p[0x06]));printf("\tSerial Number: %s\n", dmi_string(h, p[0x07]));printf("\tAsset Tag Number: %s\n", dmi_string(h, p[0x08]));printf("\tVersion: %s\n", dmi_string(h, p[0x10]));}else if(h->type == 4){printf("\nType %02d - [Processor Information]\n", h->type);printf("\tSocket Designation: %s\n", dmi_string(h, p[0x04]));printf("\tProcessor Manufacturer: %s\n", dmi_string(h, p[0x07]));printf("\tProcessor Version: %s\n", dmi_string(h, p[0x10]));printf("\tVoltage: %d (Bit0 - 5v, Bit1 - 3.3v, Bit2 - 2.9v)\n", p[0x11]&0x7);printf("\tExternal Clock: %d MHz\n", p[0x12]+p[0x13]*0x100);printf("\tMax Speed: %d MHz\n", p[0x14]+p[0x15]*0x100);printf("\tCurrent Speed: %d MHz\n", p[0x16]+p[0x17]*0x100);printf("\tSerial Number: %s\n", dmi_string(h, p[0x20]));printf("\tAsset Tag: %s\n", dmi_string(h, p[0x21]));printf("\tPart Number: %s\n", dmi_string(h, p[0x22]));}else if (h->type == 17) {if (p[0xc]+p[0xd]*0x100 == 0)continue;printf("\nType %02d - [Memory]\n", h->type);printf("\tTotal Width: %d\n", p[0x8]);printf("\tData Width:%d\n",   p[0xa]);printf("\tSize: %d MB\n",   p[0xc]+p[0xd]*0x100);printf("\tSpeed: %dMHz\n",   p[0x15]+p[0x16]*0x100);printf("\tBank Locator: %s\n", dmi_string(h, p[0x11]));printf("\tManufacturer: %s\n", dmi_string(h, p[0x17]));printf("\tSerial Number: %s\n", dmi_string(h, p[0x18]));printf("\tAsset Tag: %s\n", dmi_string(h, p[0x19]));printf("\tPart Number: %s\n", dmi_string(h, p[0x1A]));}p += h->length;while((*(WORD *)p)!=0) p++;p += 2;}//getchar();delete []buf;return 0;
}std::string GetUUIDString()
{std::string uuid;uuid = "123-abc-plm-!@#";GetSystemUUID(uuid);return uuid;
}int main(int argc, char* argv[])
{GetUUIDString();getchar();return 0;
}

Windows 下读取DMI信息的方法相关推荐

  1. 组策略中的审核策略提示 Windows无法读取模板信息的解决方法

    今天在帮客户配置2003的时候,进入组策略提示Windows无法读取模板信息,原来是因为安装设置过程中删除了guest账号,下面脚本之家小编为大家分享下解决方法吧 若组策略出现"window ...

  2. [转]cscope在windows下使用mingw编译的方法

    cscope在windows下使用mingw编译的方法      http://blog.csdn.net/mslk/archive/2007/05/06/1598513.aspx cscope在wi ...

  3. windows下读取Linux分区软件

    导读 ext3等日志型文件系统是Linux中被广泛应用的,通常是许多流行Linux发行版默认的文件系统.etx4也是Linux下的日志型文件系统,被设计作为ext3的继任者.他消除了64位存储限制,是 ...

  4. 无法读取本地或者服务器版本信息,Windows2003服务器的本地安全策略显示“windows无法读取模板信息”的终极处理解决方案。...

    Windows2003服务器的本地安全策略显示"windows无法读取模板信息"的终极处理解决方案. 近逛论坛时发现许多站长提出这样的问题,由于种种原因的服务器安全设置,结果导致w ...

  5. python操作文件的库_Python使用pyshp库读取shapefile信息的方法

    通过pyshp库,可以读写Shapefile文件,查询相关信息,github地址为 https://github.com/GeospatialPython/pyshp#reading-shapefil ...

  6. cygwin学习linux命令,cygwin 在windows下使用linux命令的方法

    cygwin 在windows下使用linux命令的方法以下文字资料是由(历史新知网www.lishixinzhi.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! 但是cygwin ...

  7. python文件读写用到的库_Python使用pyshp库读取shapefile信息的方法

    通过pyshp库,可以读写shapefile文件,查询相关信息,github地址为 import shapefile # 使用pyshp库 file = shapefile.reader(" ...

  8. iis怎么更换php版本,Windows 下PHP+IIS的安装方法(PHP版本为5.0)

    Windows 下PHP+IIS的安装方法(PHP版本为5.0) 最近需要使用下PHP相关的东西,查找了一些资料,现将PHP配置方法记录一下,以免以后忘记,呵呵,初学者,各位同学不要拍砖,开始正题,主 ...

  9. windows 下的CACTI的安装方法

    windows 下的CACTI的安装方法 记得第一次工作的时候,主管非得让我学在windows 下的CACTI的安装,把我急的,明明是Linux下的东东,硬让我在windows下面装,不过有不敢不听话 ...

最新文章

  1. 迁移学习之域自适应理论简介(Domain Adaptation Theory)
  2. Python第三方包-你了解numpy吗(numpy进阶)
  3. 久等了,「阿里妈妈技术」来啦!
  4. Java EE 8:社区想要什么?
  5. javascript window.navigator
  6. opencv-api draw
  7. 如何在GitHub上搜索提交消息?
  8. Lesson_8 上课笔记 ----继承
  9. Cascadea for Mac(强大的CSS编辑器)
  10. iOS开发之SQLite的Object-C封装
  11. 具体化和实例化的应用
  12. QQ官方单向好友删除 免软件
  13. 查看javajdk版本
  14. MAC修改hosts
  15. Bootstrap-table 如何合并相同单元格
  16. POJ 3126 Prime Path(BFS + 素数打表)
  17. VI设计中系统视觉基本要素优漫动游
  18. App应用中拨打电话
  19. web3:颠覆互联网还是白日梦一场?
  20. AD20设计规则小结(Design Rules)

热门文章

  1. 关于微擎公众号配置token验证失败原因
  2. django实训项目——图书管理系统
  3. java 取名字_Java 中获取类名的三种方法,你知道几种?
  4. 投资成本低且无需专人维护!华为云会议让沟通更高效
  5. 计算机专业研究生北京科技大学,北京科技大学在职研究生计算机学专业考研怎么样...
  6. 保养皮肤的20种方法
  7. xxl-job简单任务和分片任务
  8. 分布式缓存-Redis分片集群
  9. 《网络管理工具实用详解》涉及软件的目录
  10. 玩客云Armbian