求写程序:C++获取电脑配置信息
不知道能不能发哈,如果不让发请管理员删帖[鲜花]有偿,欢迎各位老板开价,只要能承受得起就行,哈哈
电脑的信息有主板、CPU、硬盘、内存、MAC、ip等等
其中:
主板信息包括:Motherboard_Manufacturer_Name,Motherboard_Model,Motherboard_Version,Serial_Number,System_Manufacturer_Name,System_Product_Name,System_Version,System_Serial_Number,Classis_Manufacturer_Name,Classis_Version,Classis_Serial_Number,Classis_Model
CPU信息包括:CPU品牌,CPU名称,CPU核心
硬盘信息包括:硬盘品牌,硬盘名称,硬盘序列号,硬盘固件版本,硬盘容量
内存信息包括:内存条品牌,内存条名称,内存容量
MAC信息包括:MAC地址、端口号、VLANID、老化时间
ip信息包括:IP种类(ipv4,ipv6),IP地址
需要读取之后存储在一个结构体里边
struct BIOS_Message
{
std::string Motherboard_Manufacturer_Name;
std::string Motherboard_Model;
std::string Motherboard_Version;
std::string Serial_Number;
std::string System_Manufacturer_Name;
std::string System_Product_Name;
std::string System_Version;
std::string System_Serial_Number;
std::string Classis_Manufacturer_Name;
std::string Classis_Version;
std::string Classis_Serial_Number;
std::string Classis_Model;
};
struct CUPU_Message
{
//自己照着这个规律写吧emm
};
struct PC_Message
{
struct BIOS_Message BIOS_msg;
struct CUPU_Message CPU_msg;
struct HD_Message HD_msg;
struct Memory_Message Mem_msg;
struct MAC_message MAC_msg;
struct IP_Message IP_msg;
}; 以下是一个示例程序,使用C++获取电脑配置信息,并将其存储在定义的结构体中:
#include <iostream>
#include <string>
struct BIOS_Message {
std::string Motherboard_Manufacturer_Name;
std::string Motherboard_Model;
std::string Motherboard_Version;
std::string Serial_Number;
std::string System_Manufacturer_Name;
std::string System_Product_Name;
std::string System_Version;
std::string System_Serial_Number;
std::string Classis_Manufacturer_Name;
std::string Classis_Version;
std::string Classis_Serial_Number;
std::string Classis_Model;
};
struct CPU_Message {
std::string CPU_Brand;
std::string CPU_Name;
std::string CPU_Cores;
};
struct HD_Message {
std::string HardDrive_Brand;
std::string HardDrive_Name;
std::string HardDrive_Serial_Number;
std::string HardDrive_Firmware_Version;
std::string HardDrive_Capacity;
};
struct Memory_Message {
std::string Memory_Brand;
std::string Memory_Name;
std::string Memory_Capacity;
};
struct MAC_Message {
std::string MAC_Address;
std::string Port_Number;
std::string VLAN_ID;
std::string Aging_Time;
};
struct IP_Message {
std::string IP_Type;
std::string IP_Address;
};
struct PC_Message {
BIOS_Message BIOS_msg;
CPU_Message CPU_msg;
HD_Message HD_msg;
Memory_Message Mem_msg;
MAC_Message MAC_msg;
IP_Message IP_msg;
};
int main() {
// 获取和存储电脑配置信息
PC_Message pc_info;
// 获取主板信息
pc_info.BIOS_msg.Motherboard_Manufacturer_Name = "xxx";
pc_info.BIOS_msg.Motherboard_Model = "xxx";
// ...
// 获取CPU信息
pc_info.CPU_msg.CPU_Brand = "xxx";
pc_info.CPU_msg.CPU_Name = "xxx";
// ...
// 获取硬盘信息
pc_info.HD_msg.HardDrive_Brand = "xxx";
pc_info.HD_msg.HardDrive_Name = "xxx";
// ...
// 获取内存信息
pc_info.Mem_msg.Memory_Brand = "xxx";
pc_info.Mem_msg.Memory_Name = "xxx";
// ...
// 获取MAC信息
pc_info.MAC_msg.MAC_Address = "xxx";
pc_info.MAC_msg.Port_Number = "xxx";
// ...
// 获取IP信息
pc_info.IP_msg.IP_Type = "xxx";
pc_info.IP_msg.IP_Address = "xxx";
// ...
// 打印电脑配置信息
std::cout << "BIOS Message:" << std::endl;
std::cout << "Motherboard Manufacturer Name: " << pc_info.BIOS_msg.Motherboard_Manufacturer_Name << std::endl;
std::cout << "Motherboard Model: " << pc_info.BIOS_msg.Motherboard_Model << std::endl;
// ...
std::cout << "CPU Message:" << std::endl;
std::cout << "CPU Brand: " << pc_info.CPU_msg.CPU_Brand << std::endl;
std::cout << "CPU Name: " << pc_info.CPU_msg.CPU_Name << std::endl;
// ...
// 打印其他配置信息...
return 0;
}
请注意,上述示例程序中只是模拟了获取电脑配置信息的过程,并手动赋予了一些示例值。实际中,获取电脑配置信息可能需要使用特定的库或API来与操作系统进行交互,具体的实现方式会根据操作系统和编译环境的不同而有所区别。请根据你的实际需求和使用的库进行相应的调整。
如果问题已经解决,请设置最佳答案 以下是获取电脑配置信息的C++程序:
#include <iostream>
#include <Windows.h>
#include <iphlpapi.h>
#include <sstream>
#pragma comment(lib, "iphlpapi.lib")
using namespace std;
// 获取主板信息
void getBIOSInfo(BIOS_Message& bios_msg) {
char* pBuffer = NULL;
DWORD dwBufSize = 0;
// 获取缓冲区大小
GetSystemFirmwareTable('RSMB', 0, NULL, dwBufSize);
if (dwBufSize) {
pBuffer = new char;
if (pBuffer) {
// 获取主板信息
GetSystemFirmwareTable('RSMB', 0, pBuffer, dwBufSize);
SMBIOS_HEADER* pSMBIOSHeader = (SMBIOS_HEADER*)pBuffer;
while (pSMBIOSHeader->Type != 0x00) {
if (pSMBIOSHeader->Type == 0x02) {
SMBIOS_TYPE2* pSMBIOS = (SMBIOS_TYPE2*)pSMBIOSHeader;
bios_msg.Motherboard_Manufacturer_Name = (char*)pSMBIOS + pSMBIOS->Manufacturer;
bios_msg.Motherboard_Model = (char*)pSMBIOS + pSMBIOS->Product;
bios_msg.Motherboard_Version = (char*)pSMBIOS + pSMBIOS->Version;
bios_msg.Serial_Number = (char*)pSMBIOS + pSMBIOS->SerialNumber;
break;
}
pSMBIOSHeader = (SMBIOS_HEADER*)((char*)pSMBIOSHeader + pSMBIOSHeader->Length);
}
}
delete[] pBuffer;
}
// 获取系统信息
SYSTEM_INFO sys_info;
GetSystemInfo(&sys_info);
bios_msg.System_Manufacturer_Name = "Microsoft Corporation";
bios_msg.System_Product_Name = "Virtual Machine";
bios_msg.System_Version = "None";
bios_msg.System_Serial_Number = "None";
// 获取电脑型号
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SystemInformation", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
char szData = { 0 };
DWORD dwType = REG_SZ;
DWORD dwSize = sizeof(szData);
if (RegQueryValueEx(hKey, "SystemProductName", NULL, &dwType, (LPBYTE)szData, &dwSize) == ERROR_SUCCESS) {
bios_msg.System_Product_Name = szData;
}
RegCloseKey(hKey);
}
// 获取电脑序列号
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SystemInformation", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
char szData = { 0 };
DWORD dwType = REG_SZ;
DWORD dwSize = sizeof(szData);
if (RegQueryValueEx(hKey, "SystemSKU", NULL, &dwType, (LPBYTE)szData, &dwSize) == ERROR_SUCCESS) {
bios_msg.System_Serial_Number = szData;
}
RegCloseKey(hKey);
}
// 获取计算机型号
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\SystemInformation", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
char szData = { 0 };
DWORD dwType = REG_SZ;
DWORD dwSize = sizeof(szData);
if (RegQueryValueEx(hKey, "SystemFamily", NULL, &dwType, (LPBYTE)szData, &dwSize) == ERROR_SUCCESS) {
bios_msg.Classis_Model = szData;
}
RegCloseKey(hKey);
}
}
// 获取CPU信息
void getCPUInfo(CPU_Message& cpu_msg) {
SYSTEM_INFO sys_info;
GetSystemInfo(&sys_info);
cpu_msg.CPU_brand = "Unknown";
cpu_msg.CPU_name = "Unknown";
cpu_msg.CPU_cores = sys_info.dwNumberOfProcessors;
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
char szData = { 0 };
DWORD dwType = REG_SZ;
DWORD dwSize = sizeof(szData);
if (RegQueryValueEx(hKey, "ProcessorNameString", NULL, &dwType, (LPBYTE)szData, &dwSize) == ERROR_SUCCESS) {
cpu_msg.CPU_name = szData;
}
if (RegQueryValueEx(hKey, "VendorIdentifier", NULL, &dwType, (LPBYTE)szData, &dwSize) == ERROR_SUCCESS) {
cpu_msg.CPU_brand = szData;
}
RegCloseKey(hKey);
}
}
// 获取硬盘信息
void getHDInfo(HD_Message& hd_msg) {
hd_msg.HD_brand = "Unknown";
hd_msg.HD_name = "Unknown";
hd_msg.HD_serial_number = "Unknown";
hd_msg.HD_firmware_version = "Unknown";
hd_msg.HD_capacity = 0;
// 获取硬盘信息
HANDLE hDevice = CreateFileA("\\\\.\\PhysicalDrive0", GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, NULL, NULL);
if (hDevice != INVALID_HANDLE_VALUE) {
STORAGE_PROPERTY_QUERY query;
char buffer = { 0 };
memset(&query, 0, sizeof(query));
query.PropertyId = StorageDeviceProperty;
query.QueryType = PropertyStandardQuery;
if (DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &buffer, sizeof(buffer), NULL, NULL)) {
STORAGE_DEVICE_DESCRIPTOR* pDevDesc = (STORAGE_DEVICE_DESCRIPTOR*)&buffer;
char* pVendorIdOffset = buffer + pDevDesc->VendorIdOffset;
char* pProductIdOffset = buffer + pDevDesc->ProductIdOffset;
char* pProductRevisionOffset = buffer + pDevDesc->ProductRevisionOffset;
hd_msg.HD_brand = pVendorIdOffset;
hd_msg.HD_name = pProductIdOffset;
hd_msg.HD_firmware_version = pProductRevisionOffset;
}
memset(&query, 0, sizeof(query));
query.PropertyId = StorageDeviceIdProperty;
query.QueryType = PropertyStandardQuery;
if (DeviceIoControl(hDevice, IOCTL_STORAGE_QUERY_PROPERTY, &query, sizeof(query), &buffer, sizeof(buffer), NULL, NULL)) {
STORAGE_DEVICE_ID_DESCRIPTOR* pDevIdDesc = (STORAGE_DEVICE_ID_DESCRIPTOR*)&buffer;
char* pSerialNumberOffset = buffer + pDevIdDesc->SerialNumberOffset;
hd_msg.HD_serial_number = pSerialNumberOffset;
}
GET_LENGTH_INFORMATION LengthInfo;
if (DeviceIoControl(hDevice, IOCTL_DISK_GET_LENGTH_INFO, NULL, 0, &LengthInfo, sizeof(GET_LENGTH_INFORMATION), NULL, NULL)) {
hd_msg.HD_capacity = LengthInfo.Length.QuadPart / 1024 / 1024 / 1024;
}
CloseHandle(hDevice);
}
}
// 获取内存信息
void getMemoryInfo(Memory_Message& mem_msg) {
mem_msg.Memory_brand = "Unknown";
mem_msg.Memory_name = "Unknown";
mem_msg.Memory_capacity = 0;
// 获取内存信息
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
mem_msg.Memory_capacity = statex.ullTotalPhys / 1024 / 1024 / 1024;
HKEY hKey;
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
char szData = { 0 };
DWORD dwType = REG_SZ;
DWORD dwSize = sizeof(szData);
if (RegQueryValueEx(hKey, "VendorIdentifier", NULL, &dwType, (LPBYTE)szData, &dwSize) == ERROR_SUCCESS) {
mem_msg.Memory_brand = szData;
}
RegCloseKey(hKey);
}
}
// 获取MAC地址信息
void getMACInfo(MAC_Message& mac_msg) {
mac_msg.MAC_address = "Unknown";
mac_msg.MAC_port = 0;
mac_msg.MAC_VLANID = 0;
mac_msg.MAC_aging_time = 0;
// 获取MAC地址信息
IP_ADAPTER_INFO AdapterInfo;
DWORD dwBufLen = sizeof(AdapterInfo);
DWORD dwStatus = GetAdaptersInfo(AdapterInfo, &dwBufLen);
if (dwStatus == ERROR_SUCCESS) {
PIP_ADAPTER_INFO pAdapterInfo = AdapterInfo;
while (pAdapterInfo) {
if (pAdapterInfo->Type == MIB_IF_TYPE_ETHERNET && pAdapterInfo->AddressLength == 6) {
stringstream ss;
for (int i = 0; i < pAdapterInfo->AddressLength; i++) {
ss << hex << (int)pAdapterInfo->Address[ i];
if (i < pAdapterInfo->AddressLength - 1) {
ss << ":";
}
}
mac_msg.MAC_address = ss.str();
mac_msg.MAC_port = pAdapterInfo->Index;
mac_msg.MAC_VLANID = pAdapterInfo->VlanId;
mac_msg.MAC_aging_time = pAdapterInfo->LeaseExpires;
break;
}
pAdapterInfo = pAdapterInfo->Next;
}
}
}
// 获取IP地址信息
void getIPInfo(IP_Message& ip_msg) {
ip_msg.IP_type = "Unknown";
ip_msg.IP_address = "Unknown";
// 获取IP地址信息
PIP_ADAPTER_ADDRESSES pAddresses = NULL;
ULONG ulFlags = GAA_FLAG_INCLUDE_PREFIX;
ULONG ulAddrTableSize = 0;
GetAdaptersAddresses(AF_UNSPEC, ulFlags, NULL, pAddresses, &ulAddrTableSize);
pAddresses = (PIP_ADAPTER_ADDRESSES)malloc(ulAddrTableSize);
GetAdaptersAddresses(AF_UNSPEC, ulFlags, NULL, pAddresses, &ulAddrTableSize);
PIP_ADAPTER_ADDRESSES pCurrAddresses = pAddresses;
while (pCurrAddresses) {
if (pCurrAddresses->OperStatus == IfOperStatusUp) {
if (pCurrAddresses->IfType == IF_TYPE_ETHERNET_CSMACD || pCurrAddresses->IfType == IF_TYPE_IEEE80211) {
if (pCurrAddresses->FirstUnicastAddress) {
sockaddr* pAddr = pCurrAddresses->FirstUnicastAddress->Address.lpSockaddr;
if (pAddr->sa_family == AF_INET) {
ip_msg.IP_type = "ipv4";
char szIP = { 0 };
DWORD dwSize = sizeof(szIP);
WSAAddressToStringA(pAddr, pCurrAddresses->FirstUnicastAddress->Address.iSockaddrLength, NULL, szIP, &dwSize);
ip_msg.IP_address = szIP;
}
else if (pAddr->sa_family == AF_INET6) {
ip_msg.IP_type = "ipv6";
char szIP = { 0 };
DWORD dwSize = sizeof(szIP);
WSAAddressToStringA(pAddr, pCurrAddresses->FirstUnicastAddress->Address.iSockaddrLength, NULL, szIP, &dwSize);
ip_msg.IP_address = szIP;
}
}
break;
}
}
pCurrAddresses = pCurrAddresses->Next;
}
free(pAddresses);
}
// 获取电脑配置信息
void getPCInfo(PC_Message& pc_msg) {
getBIOSInfo(pc_msg.BIOS_msg);
getCPUInfo(pc_msg.CPU_msg);
getHDInfo(pc_msg.HD_msg);
getMemoryInfo(pc_msg.Mem_msg);
getMACInfo(pc_msg.MAC_msg);
getIPInfo(pc_msg.IP_msg);
}
int main() {
PC_Message pc_msg;
getPCInfo(pc_msg);
cout << "BIOS信息:" << endl;
cout << "主板制造商:" << pc_msg.BIOS_msg.Motherboard_Manufacturer_Name << endl;
cout << "主板型号:" << pc_msg.BIOS_msg.Motherboard_Model << endl;
cout << "主板版本号:" << pc_msg.BIOS_msg.Motherboard_Version << endl;
cout << "主板序列号:" << pc_msg.BIOS_msg.Serial_Number << endl;
cout << "系统制造商:" << pc_msg.BIOS_msg.System_Manufacturer_Name << endl;
cout << "系统产品名称:" << pc_msg.BIOS_msg.System_Product_Name << endl;
cout << "系统版本号:" << pc_msg.BIOS_msg.System_Version << endl;
cout << "系统序列号:" << pc_msg.BIOS_msg.System_Serial_Number << endl;
cout << "计算机制造商:" << pc_msg.BIOS_msg.Classis_Manufacturer_Name << endl;
cout << "计算机型号:" << pc_msg.BIOS_msg.Classis_Model << endl;
cout << "计算机版本号:" << pc_msg.BIOS_msg.Classis_Version << endl;
cout << "CPU信息:" << endl;
cout << "CPU品牌:" << pc_msg.CPU_msg.CPU_brand << endl;
cout << "CPU名称:" << pc_msg.CPU_msg.CPU_name << endl;
cout << "CPU核心数:" << pc_msg.CPU_msg.CPU_cores << endl;
cout << "硬盘信息:" << endl;
cout << "硬盘品牌:" << pc_msg.HD_msg.HD_brand << endl;
cout << "硬盘名称:" << pc_msg.HD_msg.HD_name << endl;
cout << "硬盘序列号:" << pc_msg.HD_msg.HD_serial_number << endl;
cout << "硬盘固件版本:" << pc_msg.HD_msg.HD_firmware_version << endl;
cout << "硬盘容量:" << pc_msg.HD_msg.HD_capacity << "GB" << endl;
cout << "内存信息:" << endl;
cout << "内存品牌:" << pc_msg.Mem_msg.Memory_brand << endl;
cout << "内存名称:" << pc_msg.Mem_msg.Memory_name << endl;
cout << "内存容量:" << pc_msg.Mem_msg.Memory_capacity << "GB" << endl;
cout << "MAC地址信息:" << endl;
cout << "MAC地址:" << pc_msg.MAC_msg.MAC_address << endl;
cout << "MAC端口号:" << pc_msg.MAC_msg.MAC_port << endl;
cout << "MAC VLAN ID:" << pc_msg.MAC_msg.MAC_VLANID << endl;
cout << "MAC老化时间:" << pc_msg.MAC_msg.MAC_aging_time << endl;
cout << "IP地址信息:" << endl;
cout << "IP种类:" << pc_msg.IP_msg.IP_type << endl;
cout << "IP地址:" << pc_msg.IP_msg.IP_address << endl;
return 0;
}
注意:获取电脑配置信息需要管理员权限,需要以管理员身份运行程序。 isdkz 发表于 2023-9-16 11:43
以下是获取电脑配置信息的C++程序:
这个程序一片红啊555
页:
[1]