近日研究__cpuidex的用法,查询到的相关示例都比较复杂,所以本人简化了一部分内容,重新写了一个简单的例子,仅获取CPU序列号,最终结果与通过WMIC命令查询的结果保持一致。

代码示例

#include <iostream>
#include <array>
#include <intrin.h>
#include <vector>
#include <cstring>
using std::cout;int main()
{std::array<int, 4> cpui;    //#include <array>// Calling __cpuid with 0x0 as the function_id argument  // gets the number of the highest valid function ID.  什么是function ID?__cpuid(cpui.data(), 0x0);    //cpui[0] = "funcition_id的最大值"int nIds_ = cpui[0];std::vector<std::array<int, 4>> data_;  //保存遍历到的所有cpui的值    for (int i=0;i<=nIds_;++i){__cpuidex(cpui.data(), i, 0);data_.push_back(cpui);}//reinterpret_cast<int*>(vendor) //*reinterpret_cast<int*>(vendor)//索引0 0+4 0+8的值构成了CPU芯片的名称char vendor[0x20] = { 0 };*reinterpret_cast<int*>(vendor) = data_[0][1];*reinterpret_cast<int*>(vendor + 4) = data_[0][3];*reinterpret_cast<int*>(vendor + 8) = data_[0][2];  // vendor="GenuineIntel"    std::string vendor_ = vendor;bool isIntel_ = false;bool isAMD = false;if ("GenuineIntel" == vendor_){isIntel_ = true;    //厂商为INTEL}else if ("AuthenticAMD"==vendor_){isAMD = true;       //厂商为AMD}char vendor_serialnumber[0x14] = { 0 };sprintf_s(vendor_serialnumber, sizeof(vendor_serialnumber), "%08X%08X", data_[1][3], data_[1][0]);//用“wmic cpu get processorid”获取的结果进行比对,结果应该是一致的。    //vendor_serialnumber = "BFEBFBFF000406E3";    std::cout << "ProcessorId is [ " << vendor_serialnumber << " ]" << std::endl;return 0;
}

Generates the cpuid instruction that is available on x86 and x64. This instruction queries the processor for information about supported features and the CPU type.

Syntax 
void __cpuid( 
int cpuInfo[4], 
int function_id 
);

void __cpuidex( 
int cpuInfo[4], 
int function_id, 
int subfunction_id 
);

Parameters 
[out] cpuInfo 
An array of four integers that contains the information returned in EAX, EBX, ECX, and EDX about supported features of the CPU.

[in] function_id 
A code that specifies the information to retrieve, passed in EAX.

[in] subfunction_id 
An additional code that specifies information to retrieve, passed in ECX.

Requirements 
Header file <tintrin.h>

参考文献

【MSDN】__cpuid, __cpuidex

__cpuidex读取CPU序列号相关推荐

  1. VC读取硬盘序列号与CPU序列号

    所需头文件 #include "stdafx.h" // VC6#include <iostream> #include <string> #include ...

  2. 关于CPU序列号的问题,以及如何获取×64下CPU的ProcessorID

    前几天经过查资料,得到网络上获取CPU序列号的方法是错误的,首先我找到了一篇论文,这篇论文里面是这么说的: 这篇论文是错误的.这篇是错误的这篇是错误的!!!!!!!!! 2.CPU序列号 CPU序列号 ...

  3. python wmi读取网卡MAC地址、CPU序列号、硬盘序列号、主板序列号、BIOS序列号

    序列号相当于电脑的身份证号,是硬件出厂时,厂商写在硬件里的唯一识别码,具有唯一性和不可修改性.很多正版软件以此来识别用户电脑,限制安装. import uuid import wmi def get_ ...

  4. 用C#获取硬盘序列号,CPU序列号,网卡MAC地址

    这个问题首先得考虑的就是你的硬盘是不是SCSI硬盘 如果是,那么根本不存在"物理序列号",只可能取得卷标的序列号 如果是卷标序列号,要注意的是每次格式化硬盘的时候这个序列号都会变 ...

  5. Android 获取cpu序列号

    我们这一篇主要就是讲我们的android里的智能手机的cpu,其实主要展现的就是我们android是多么的强大.好了代码很少,也应该算很简单了,就不和大家说了.我们还是来看看代码吧: /** * 获取 ...

  6. java MacBook air,macbook pro 与 macbook air 的区别!(前者是高配?java中如何读取主板序列号、硬盘序列号、MAC地址...

    所以我想问的重点是?(本人使用苹果①向用于上网?整体性能呢:air那么薄,那么轻,请问它的硬盘对比pro有什么利弊,对于air我①直用macbook pro,②年换①次,今年由于①③寸的并没有使用i系 ...

  7. C语言获取硬件信息(CPU序列号,硬盘序列号,网卡IP、MAC地址、是否插入网线)

    目录 一.前言 二.代码实现 2.1 获取CPU序列号 2.2 获取硬盘序列号 2.3 获取网卡信息 附:源代码下载 一.前言   本文主要介绍Linux和Windows下使用C语言获取各种硬件信息, ...

  8. Windows/Linux获取Mac地址和CPU序列号实现

    UUID(Universally Unique Identifier)即通用唯一标识符,是指在一台机器上生成的数字,保证在全球范围的唯一性.可用的开源库如libuuid,可参考https://blog ...

  9. C++ 硬件信息 获取CPU序列号

    获取计算机CPU序列号的方法很多,这里采用的是命令行的形式获取,可以获取CPU的序列号,很简单,直接上代码. [1]头文件 #if !defined(AFX_14BEC153_17B9_47BE_84 ...

最新文章

  1. 模糊数学笔记:二、模糊截集与分解定理
  2. 在config.php文件中,写好了config文件怎么在PHP文件里按条件查询
  3. composer update 的时候提示the requested PHP extension pcntl is missing from your system.的方法处理
  4. 她说:我希望你好好写代码
  5. war包部署-打包测试
  6. 获取input file绝对路径_IO--File对象
  7. 1.1 HTML5简介
  8. 知乎:学习分布式系统需要怎样的知识?
  9. postgresql 身份证、手机号、营业执照验证脚本
  10. hadoop put命令的格式_【Hadoop篇】--Hadoop常用命令总结
  11. 安装Linux系统不分区的问题,浅谈linux系统的分区问题
  12. All-Pay Contests 论文定理推导(博弈论+机制设计)
  13. 微信小程序 + shiro 实现登录(安全管理) —— 保姆级教学
  14. 赶紧更新!PC版微信被曝高危0day漏洞;特斯拉Autopilot源码窃取案尘埃落定
  15. 谁又在乎过你呢“main()之泪伤”
  16. 手机百度打不开html网页,手机百度为什么打不开网页 网页打不开解决方法
  17. mocha java_Mocha
  18. DNS-over-HTTPS 的下一代是 DNS ON BLOCKCHAIN
  19. 电脑桌面怎么设置html背景图,css中如何设置背景图片?
  20. 直播 | 企业级应用Service Management Automation X(SMAX)的微服务之路

热门文章

  1. 【原创】分享一些机器学习和深度学习的学习资料
  2. 前Duolingo秦龙博士归国创业:情定K12个性化学习
  3. 年末盘点 2016 年最严重的 7 起 DDoS 攻击事件
  4. vmware虚拟机redhat7.2下docker容器安装hadoop
  5. CollegeStudent
  6. C#开发微信门户及应用(9)-微信门户菜单管理及提交到微信服务器
  7. Install matplotlib Error: src/ft2font.h:16:22: fatal error: ft2build.h: No such file or directory
  8. [备忘]几种即见即所得Web编辑器优缺点比较
  9. Build RESTful client
  10. 文件系统损坏导致数据文件异常恢复----惜分飞