|
C/C++ 怎么最简单获得CPU ID 和 系统盘 序列号
希望有大佬能将两份源码翻译成火山代码并分享上来,谢谢!!
源码1:-------------------------------------------------------------------
#include <stdio.h>
#include <windows.h>
#include <cpuid.h>
int main()
{
unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
__cpuid(1, eax, ebx, ecx, edx);
printf("rocessorId: %08X%08X\n", edx, eax); // cpuid 格式同 wmic cpu get processorid
printf("CPU Features: %08X-%08X-%08X-%08X\n", eax, ebx, ecx, edx);
DWORD serial_number = 0;
char file_system_name[MAX_PATH + 1] = "";
if (GetVolumeInformation("C:\\", NULL, MAX_PATH + 1, &serial_number,
NULL, NULL, file_system_name, MAX_PATH + 1))
printf("Hard Disk ID: %08X\t%s\n", serial_number, file_system_name);
else
perror("GetVolumeInformation");
}
源码2:-------------------------------------------------------------------
#include <windows.h>#include <stdio.h>int main(){ UUID uuid; UuidCreate(&uuid); // 使用 Windows API 中的 UuidCreate() 函数来生成 UUID // UUID: 07e4bca4-61f2-4485-aed2-9fea6de42d48 // 需要链接库 librpcrt4.a char *uuid_str; UuidToStringA(&uuid, (RPC_CSTR*)&uuid_str); // 为 UUID 字符串分配动态内存 printf("UUID: %s\n", uuid_str); RpcStringFreeA((RPC_CSTR*)&uuid_str); // 释放 UUID 字符串动态内存 return 0;}
转自吾爱论坛
|
|