Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need to get cpu processorID from c++ code

What I have tried:

in command prompt we can write wmic cpu getprocessorid
how to execute above command from c++ code?
Posted
Updated 2-Feb-20 17:37pm

 
Share this answer
 
Comments
Shao Voon Wong 2-Feb-20 4:33am    
5! I think this is exactly what OP needs instead!
WMIC is the command-line interface to the Windows Management Instrumentation API. You have to write C++ code to directly access the WMI API. According to this at Microsoft Docs[^] it has been effectively deprecated and this API (MI)[^] should be used.

A search here [^] brings up a fair number of code samples that can use for WMI but not so much for MI.

BTW - I knew nothing about WMI until I did a few searches. You should work on your searching skills. There are more search engines around than just google.
 
Share this answer
 
v2
Thanks veryne for trying to help
Finally i got it working in c++
// WMI.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


#include <array>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <string>
#include<conio.h>
std::string GetProcessorId() {
	std::array<int, 4> cpuInfo;
	__cpuid(cpuInfo.data(), 1);
	std::ostringstream buffer;
	buffer
		<< std::uppercase << std::hex << std::setfill('0')
		<< std::setw(8) << cpuInfo.at(3)
		<< std::setw(8) << cpuInfo.at(0);
	return buffer.str();
}

int main(void) {
	std::cout << "Processor Serial number is:  ";
		std::cout<<GetProcessorId() << std::endl;
	_getch();
	return 0;
}
 
Share this answer
 
Why don't you just execute the WMI query directly instead of shelling out to an external tool to do it?

WMI C++ Application Examples - Win32 apps | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900