1. 使用cmd获取cpu id

在 CMD中输入如下命令:

wmic cpu get processorid

2. 使用源代码编译获取 cpu id:(借码)三个源代码文件

调试通过

原文链接1

原文链接2

//get_cpu_id.h

//get_cpu_id.h#pragma once#include <windows.h>
#include <stdio.h>
#include <string>
#include <intrin.h>// same function as:    wmic cpu get processoridclass CGetCPUId
{
public:CGetCPUId();virtual ~CGetCPUId();public:std::string            GetId();};

//get_cpu_id.cpp

//get_cpu_id.cpp#include "get_cpu_id.h"CGetCPUId::CGetCPUId()
{
}CGetCPUId::~CGetCPUId()
{}std::string CGetCPUId::GetId()
{/** only win32std::string strCPUId;unsigned long s1, s2;char buf[32] = { 0 };__asm{mov eax, 01hxor edx, edxcpuidmov s1, edxmov s2, eax}if (s1){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s1);strCPUId += buf;}if (s2){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s2);strCPUId += buf;}__asm{mov eax, 03hxor ecx, ecxxor edx, edxcpuidmov s1, edxmov s2, ecx}if (s1){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s1);strCPUId += buf;}if (s2){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s2);strCPUId += buf;}return strCPUId;*/std::string strCPUId;unsigned long s1, s2;char buf[32] = { 0 };INT32 Infobuf[4];
#if defined(_WIN64)// 64位下不支持内联汇编. 应使用__cpuid、__cpuidex等Intrinsics函数。__cpuid(Infobuf, 1);s1 = Infobuf[3];s2 = Infobuf[0];
#else__asm{mov eax, 01hxor ecx, ecxxor edx, edxcpuidmov s1, edxmov s2, ecx}
#endifif (s1){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s1);strCPUId += buf;}if (s2){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s2);strCPUId += buf;}#if defined(_WIN64)// 64位下不支持内联汇编. 应使用__cpuid、__cpuidex等Intrinsics函数。__cpuid(Infobuf, 3);s1 = Infobuf[3];s2 = Infobuf[0];
#else__asm{mov eax, 03hxor ecx, ecxxor edx, edxcpuidmov s1, edxmov s2, ecx}
#endifif (s1){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s1);strCPUId += buf;}if (s2){memset(buf, 0, 32);sprintf_s(buf, 32, "%08X", s2);strCPUId += buf;}return strCPUId;}

//main_app.cpp

//main_app.cpp#include "get_cpu_id.h"
#include <iostream>using namespace std;int main(int argc, char* argv[])
{CGetCPUId        GetCPUId;cout << "CPUID:" << GetCPUId.GetId() << endl;getchar();return 0;
}

3. 获取cpu 其他信息

一个cpp文件

原文链接3

//Micro_cpu_info_app.cpp

//Micro_cpu_info_app.cpp// Micro_CPUID_sample_app.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
// InstructionSet.cpp
// Compile by using: cl /EHsc /W4 InstructionSet.cpp
// processor: x86, x64
// Uses the __cpuid intrinsic to get information about
// CPU extended instruction set support.#include <iostream>
#include <vector>
#include <bitset>
#include <array>
#include <string>
#include <intrin.h>class InstructionSet
{// forward declarationsclass InstructionSet_Internal;public:// gettersstatic std::string Vendor(void) { return CPU_Rep.vendor_; }static std::string Brand(void) { return CPU_Rep.brand_; }static bool SSE3(void) { return CPU_Rep.f_1_ECX_[0]; }static bool PCLMULQDQ(void) { return CPU_Rep.f_1_ECX_[1]; }static bool MONITOR(void) { return CPU_Rep.f_1_ECX_[3]; }static bool SSSE3(void) { return CPU_Rep.f_1_ECX_[9]; }static bool FMA(void) { return CPU_Rep.f_1_ECX_[12]; }static bool CMPXCHG16B(void) { return CPU_Rep.f_1_ECX_[13]; }static bool SSE41(void) { return CPU_Rep.f_1_ECX_[19]; }static bool SSE42(void) { return CPU_Rep.f_1_ECX_[20]; }static bool MOVBE(void) { return CPU_Rep.f_1_ECX_[22]; }static bool POPCNT(void) { return CPU_Rep.f_1_ECX_[23]; }static bool AES(void) { return CPU_Rep.f_1_ECX_[25]; }static bool XSAVE(void) { return CPU_Rep.f_1_ECX_[26]; }static bool OSXSAVE(void) { return CPU_Rep.f_1_ECX_[27]; }static bool AVX(void) { return CPU_Rep.f_1_ECX_[28]; }static bool F16C(void) { return CPU_Rep.f_1_ECX_[29]; }static bool RDRAND(void) { return CPU_Rep.f_1_ECX_[30]; }static bool MSR(void) { return CPU_Rep.f_1_EDX_[5]; }static bool CX8(void) { return CPU_Rep.f_1_EDX_[8]; }static bool SEP(void) { return CPU_Rep.f_1_EDX_[11]; }static bool CMOV(void) { return CPU_Rep.f_1_EDX_[15]; }static bool CLFSH(void) { return CPU_Rep.f_1_EDX_[19]; }static bool MMX(void) { return CPU_Rep.f_1_EDX_[23]; }static bool FXSR(void) { return CPU_Rep.f_1_EDX_[24]; }static bool SSE(void) { return CPU_Rep.f_1_EDX_[25]; }static bool SSE2(void) { return CPU_Rep.f_1_EDX_[26]; }static bool FSGSBASE(void) { return CPU_Rep.f_7_EBX_[0]; }static bool BMI1(void) { return CPU_Rep.f_7_EBX_[3]; }static bool HLE(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[4]; }static bool AVX2(void) { return CPU_Rep.f_7_EBX_[5]; }static bool BMI2(void) { return CPU_Rep.f_7_EBX_[8]; }static bool ERMS(void) { return CPU_Rep.f_7_EBX_[9]; }static bool INVPCID(void) { return CPU_Rep.f_7_EBX_[10]; }static bool RTM(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_7_EBX_[11]; }static bool AVX512F(void) { return CPU_Rep.f_7_EBX_[16]; }static bool RDSEED(void) { return CPU_Rep.f_7_EBX_[18]; }static bool ADX(void) { return CPU_Rep.f_7_EBX_[19]; }static bool AVX512PF(void) { return CPU_Rep.f_7_EBX_[26]; }static bool AVX512ER(void) { return CPU_Rep.f_7_EBX_[27]; }static bool AVX512CD(void) { return CPU_Rep.f_7_EBX_[28]; }static bool SHA(void) { return CPU_Rep.f_7_EBX_[29]; }static bool PREFETCHWT1(void) { return CPU_Rep.f_7_ECX_[0]; }static bool LAHF(void) { return CPU_Rep.f_81_ECX_[0]; }static bool LZCNT(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_ECX_[5]; }static bool ABM(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[5]; }static bool SSE4a(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[6]; }static bool XOP(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[11]; }static bool TBM(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_ECX_[21]; }static bool SYSCALL(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[11]; }static bool MMXEXT(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[22]; }static bool RDTSCP(void) { return CPU_Rep.isIntel_ && CPU_Rep.f_81_EDX_[27]; }static bool _3DNOWEXT(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[30]; }static bool _3DNOW(void) { return CPU_Rep.isAMD_ && CPU_Rep.f_81_EDX_[31]; }private:static const InstructionSet_Internal CPU_Rep;class InstructionSet_Internal{public:InstructionSet_Internal(): nIds_{ 0 },nExIds_{ 0 },isIntel_{ false },isAMD_{ false },f_1_ECX_{ 0 },f_1_EDX_{ 0 },f_7_EBX_{ 0 },f_7_ECX_{ 0 },f_81_ECX_{ 0 },f_81_EDX_{ 0 },data_{},extdata_{}{//int cpuInfo[4] = {-1};std::array<int, 4> cpui;// Calling __cpuid with 0x0 as the function_id argument// gets the number of the highest valid function ID.__cpuid(cpui.data(), 0);nIds_ = cpui[0];for (int i = 0; i <= nIds_; ++i){__cpuidex(cpui.data(), i, 0);data_.push_back(cpui);}// Capture vendor stringchar vendor[0x20];memset(vendor, 0, sizeof(vendor));*reinterpret_cast<int*>(vendor) = data_[0][1];*reinterpret_cast<int*>(vendor + 4) = data_[0][3];*reinterpret_cast<int*>(vendor + 8) = data_[0][2];vendor_ = vendor;if (vendor_ == "GenuineIntel"){isIntel_ = true;}else if (vendor_ == "AuthenticAMD"){isAMD_ = true;}// load bitset with flags for function 0x00000001if (nIds_ >= 1){f_1_ECX_ = data_[1][2];f_1_EDX_ = data_[1][3];}// load bitset with flags for function 0x00000007if (nIds_ >= 7){f_7_EBX_ = data_[7][1];f_7_ECX_ = data_[7][2];}// Calling __cpuid with 0x80000000 as the function_id argument// gets the number of the highest valid extended ID.__cpuid(cpui.data(), 0x80000000);nExIds_ = cpui[0];char brand[0x40];memset(brand, 0, sizeof(brand));for (int i = 0x80000000; i <= nExIds_; ++i){__cpuidex(cpui.data(), i, 0);extdata_.push_back(cpui);}// load bitset with flags for function 0x80000001if (nExIds_ >= 0x80000001){f_81_ECX_ = extdata_[1][2];f_81_EDX_ = extdata_[1][3];}// Interpret CPU brand string if reportedif (nExIds_ >= 0x80000004){memcpy(brand, extdata_[2].data(), sizeof(cpui));memcpy(brand + 16, extdata_[3].data(), sizeof(cpui));memcpy(brand + 32, extdata_[4].data(), sizeof(cpui));brand_ = brand;}};int nIds_;int nExIds_;std::string vendor_;std::string brand_;bool isIntel_;bool isAMD_;std::bitset<32> f_1_ECX_;std::bitset<32> f_1_EDX_;std::bitset<32> f_7_EBX_;std::bitset<32> f_7_ECX_;std::bitset<32> f_81_ECX_;std::bitset<32> f_81_EDX_;std::vector<std::array<int, 4>> data_;std::vector<std::array<int, 4>> extdata_;};
};// Initialize static member data
const InstructionSet::InstructionSet_Internal InstructionSet::CPU_Rep;// Print out supported instruction set extensions
int main()
{auto& outstream = std::cout;auto support_message = [&outstream](std::string isa_feature, bool is_supported) {outstream << isa_feature << (is_supported ? " supported" : " not supported") << std::endl;};std::cout << InstructionSet::Vendor() << std::endl;std::cout << InstructionSet::Brand() << std::endl;support_message("3DNOW", InstructionSet::_3DNOW());support_message("3DNOWEXT", InstructionSet::_3DNOWEXT());support_message("ABM", InstructionSet::ABM());support_message("ADX", InstructionSet::ADX());support_message("AES", InstructionSet::AES());support_message("AVX", InstructionSet::AVX());support_message("AVX2", InstructionSet::AVX2());support_message("AVX512CD", InstructionSet::AVX512CD());support_message("AVX512ER", InstructionSet::AVX512ER());support_message("AVX512F", InstructionSet::AVX512F());support_message("AVX512PF", InstructionSet::AVX512PF());support_message("BMI1", InstructionSet::BMI1());support_message("BMI2", InstructionSet::BMI2());support_message("CLFSH", InstructionSet::CLFSH());support_message("CMPXCHG16B", InstructionSet::CMPXCHG16B());support_message("CX8", InstructionSet::CX8());support_message("ERMS", InstructionSet::ERMS());support_message("F16C", InstructionSet::F16C());support_message("FMA", InstructionSet::FMA());support_message("FSGSBASE", InstructionSet::FSGSBASE());support_message("FXSR", InstructionSet::FXSR());support_message("HLE", InstructionSet::HLE());support_message("INVPCID", InstructionSet::INVPCID());support_message("LAHF", InstructionSet::LAHF());support_message("LZCNT", InstructionSet::LZCNT());support_message("MMX", InstructionSet::MMX());support_message("MMXEXT", InstructionSet::MMXEXT());support_message("MONITOR", InstructionSet::MONITOR());support_message("MOVBE", InstructionSet::MOVBE());support_message("MSR", InstructionSet::MSR());support_message("OSXSAVE", InstructionSet::OSXSAVE());support_message("PCLMULQDQ", InstructionSet::PCLMULQDQ());support_message("POPCNT", InstructionSet::POPCNT());support_message("PREFETCHWT1", InstructionSet::PREFETCHWT1());support_message("RDRAND", InstructionSet::RDRAND());support_message("RDSEED", InstructionSet::RDSEED());support_message("RDTSCP", InstructionSet::RDTSCP());support_message("RTM", InstructionSet::RTM());support_message("SEP", InstructionSet::SEP());support_message("SHA", InstructionSet::SHA());support_message("SSE", InstructionSet::SSE());support_message("SSE2", InstructionSet::SSE2());support_message("SSE3", InstructionSet::SSE3());support_message("SSE4.1", InstructionSet::SSE41());support_message("SSE4.2", InstructionSet::SSE42());support_message("SSE4a", InstructionSet::SSE4a());support_message("SSSE3", InstructionSet::SSSE3());support_message("SYSCALL", InstructionSet::SYSCALL());support_message("TBM", InstructionSet::TBM());support_message("XOP", InstructionSet::XOP());support_message("XSAVE", InstructionSet::XSAVE());
}

Windows上获取cpu info, cpuid, cpu id 方法整理相关推荐

  1. java 线程不足_jvm - 如何在没有运行缺点的Windows上获取Java进程的线程和堆转储...

    jvm - 如何在没有运行缺点的Windows上获取Java进程的线程和堆转储 我有一个Java应用程序,我从控制台运行,然后控制台执行另一个Java进程. 我想获得该子进程的线程/堆转储. 在Uni ...

  2. LVGL 之 windows 上 lvgl 模拟器基于 Visual Studio 搭建方法的简单整理

    LVGL 之 windows 上 lvgl 模拟器 基于 Visual Studio 搭建方法的简单整理 目录 LVGL 之 windows 上 lvgl 模拟器 基于 Visual Studio 搭 ...

  3. windows 上Miktex的镜像源最新配置方法

    windows 上Miktex的镜像源最新配置方法 安装完Miktex之后,试了试网上的例子,发现要安装包,但是默认的国外的(反正连接失败),就去搜如何更换国内镜像源,然而,然并卵,特别是一个百度的一 ...

  4. arm linux读cpu id,基于ARM架构的芯片获取CPU信息(cpuID)的多种方法

    由于工作的原因,要获取到ARM芯片的cpuid. 了解下存储cpu信息的寄存器内容: CPUID寄存器内容: 字段名:Implementer(venter 销售ID)|Variant(大版本号) | ...

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

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

  6. 你如何在java中获取线程堆_如何在Windows上获取未在控制台中运行的Java进程的线程和堆转储...

    问题 我有一个Java应用程序,我从控制台运行,然后控制台执行另一个Java进程.我想获得该子进程的线程/堆转储. 在Unix上,我可以做akill -3 但是在Windows AFAIK上获取线程转 ...

  7. Windows下获取usb视频设备vendor id和product id的4种方法

    之前在https://blog.csdn.net/fengbingchun/article/details/103507754 博文中介绍过如何在Linux获取usb视频设备的vendor id和pr ...

  8. windows上获取系统时间

    一.  通过time_t和tm struct tm {int tm_sec; // seconds after the minute - [0, 60] including leap secondin ...

  9. Windows上获取文件大小的几种方法及获取文件夹大小方法

    文章来自:https://blog.csdn.net/mfcing/article/details/53184921 获取文件大小 Windows提供了好几个API函数来获取文件大小,还可以使用标准C ...

最新文章

  1. Linux网卡重启后会有哪些更新,问题:linux系统经常出现断网的情况,重启之后系统恢复正常...
  2. 一文让你搞懂YOLO难关!
  3. python类相关的研究生专业-为什么很多大学生甚至研究生抛弃专业去做码农呢?...
  4. 电影院票务管理系统数据库设计(1)
  5. javascript数组的操作
  6. [na]华为acl(traffic-filter)和dhcp管理
  7. kotlin 判断数字_Kotlin程序可以逆转数字
  8. 极兔速递完成17.35亿美元融资?回应:不实消息
  9. 解压tar.xz文件
  10. n9 android模拟器,Android软件将兼容诺基亚N9
  11. 在Simulink中对S 函数进行参数传递的三种方法
  12. 自学c语言难,自学C语言/C++到底难在哪里?
  13. 2022年全球市场HTCC陶瓷封装总体规模、主要生产商、主要地区、产品和应用细分研究报告
  14. 从吃凉的就会肚子疼,不敢吃可爱多以下的雪糕,吃饱后去逛街肚子就会胀,到后来吃饭的时候就胃疼解决办法
  15. linux查看多核cpu运行状态,Linux下查看多核CPU信息详解
  16. 华为v2服务器系统安装系统,华为服务器RH 2288H v2安装系统
  17. 小程序源码:未来老婆查询生成器-多玩法安装简单
  18. 手机为什么显示服务器升级,支付宝提示的支付服务升级是什么意思?
  19. FPS游戏通用自瞄与透视算法详解!!
  20. 钰泰半导体ETA4034爆款OVP+OCP+NTC+OTP+FAULT五合一方案, 兼容BQ24314

热门文章

  1. 「西瓜书」阅读笔记——决策树
  2. 四川大学2014年数学分析考研试题
  3. Leetcode_1823_找出游戏的获胜者_约瑟夫环
  4. C# Serializable标签 和序列化
  5. 开发简单Android聊天软件(7)
  6. 海明码检错与纠错,经典例子讲解~
  7. Mysql视图和触发器
  8. 在开发环境使用 TiUP安装TiDB集群
  9. 如何设计一个权限管理模块?
  10. Django+redis+celery实现异步任务