这个需要相关的库以及API。
给你一个获取cpu信息的函数:
DWORD MyCPUSpeed()
{
BSTR bstrMyCpuName=NULL;
BSTR bstrMyPropName = NULL;
VARIANT pVal;
char szText[256];
int nCpuNum=0;
DWORD dwCpuSpeed=0;
IWbemClassObject pCpuInst=NULL;
IWbemQualifierSet pQualSet = NULL;
bstrMyPropName = SysAllocString(L"CurrentClockSpeed");
if(bstrMyPropName == NULL)
{
return dwCpuSpeed;
}
while(1)
{
memset(szText,0,sizeof(szText));
sprintf(szText,"Win32_ProcessorDeviceID=\"CPU%d\"", nCpuNum);
bstrMyCpuName = _bstr_t(szText);
if(bstrMyCpuName == NULL)
{
break;
}
if(pSvc->GetObject(bstrMyCpuName, 0L, NULL, &pCpuInst, NULL) != S_OK)
{
break;
}
if(pCpuInst->Get(bstrMyPropName, 0L, &pVal, NULL, NULL) == S_OK)
{
nCpuNum++;
dwCpuSpeed += pVallVal;
}
VariantClear(&pVal);
SysFreeString(bstrMyCpuName);
bstrMyCpuName = NULL;
}
if(bstrMyPropName != NULL)
{
SysFreeString(bstrMyPropName);
bstrMyPropName = NULL;
}
if(bstrMyCpuName != NULL)
{
SysFreeString(bstrMyCpuName);
bstrMyCpuName = NULL;
}
memset(szText,0,sizeof(szText));
sprintf(szText, "CPU个数: %d, CPU频率: %ld Mhz", nCpuNum, dwCpuSpeed);
cout<<"------------------------"<<szText<<"-------------------------"<<endl;
return dwCpuSpeed;
}
CString GetMacAddress()
/
通过WMI取第一块活动网卡地址,事先需要调用过CoInitialize()初始化COM
/
{
HRESULT hRes;
hRes = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
if (FAILED(hRes))
return _T("");
IWbemLocator pLoc = NULL;
hRes = CoCreateInstance(CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID)&pLoc);
if (FAILED(hRes))
return _T("");
IWbemServices pSvc = NULL;
hRes = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"), NULL, NULL, 0,
NULL, 0, 0, &pSvc);
if (FAILED(hRes))
{
pLoc->Release();
return _T("");
}
hRes = CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE,
NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_DEFAULT);
if (FAILED(hRes))
{
pSvc->Release();
pLoc->Release();
return _T("");
}
IEnumWbemClassObject pEnumerator = NULL;
hRes = pSvc->ExecQuery(_bstr_t(L"WQL"),
_bstr_t(L"SELECT FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL, &pEnumerator);
if (FAILED(hRes))
{
pSvc->Release();
pLoc->Release();
return _T("");
}
CString szMacAddress = _T("");
while (true)
{
IWbemClassObject pclsObj = NULL;
ULONG uReturn = 0;
hRes = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
if (FAILED(hRes) || !uReturn)
break;
VARIANT vtProp;
VariantInit(&vtProp);
if (SUCCEEDED(pclsObj->Get(L"MACAddress", 0, &vtProp, 0, 0)))
{
if (V_VT(&vtProp) == VT_BSTR)
{
szMacAddress = vtPropbstrVal;
VariantClear(&vtProp);
pclsObj->Release();
break;
}
VariantClear(&vtProp);
}
pclsObj->Release();
}
pEnumerator->Release();
pSvc->Release();
pLoc->Release();
return szMacAddress;
}
------解决方案--------------------奥,那个DLL大概在02年左右整理的好像,时间太久了,应该是不支持vsita的,楼主看看这段代码是否有用?我是拷贝来的:/ //函数名称:GetDriverInfomation //函数功能:得到驱动器的信息 //参数1:bAlpha - BYTE型,驱动器的代号A-Z(a-z) //参数2:iGTI_TYPE - int,将要获取的驱动器信息类型 // GDI_VOLUMENAME 得到驱动器名字 // GDI_VOLUMESERIALNUMBER 得到驱动器序列号 // GDI_VOLUMEFILESYSTEM 得到驱动器文件系统 // GDI_VOLUMETYPE 得到驱动器类型 // GDI_VOLUMESIZE 得到驱动器总大小 // GDI_VOLUMEFREESIZE 得到驱动器剩余大小 //返回值:CString型,所要得到的驱动器信息的字符串表达 //例子:得到C盘的名字GetDriverInfomation('C',GDI_VOLUMENAME) / #define GDI_VOLUMENAME 0 #define GDI_VOLUMESERIALNUMBER 1 #define GDI_VOLUMEFILESYSTEM 2 #define GDI_VOLUMETYPE 3 #define GDI_VOLUMESIZE 4 #define GDI_VOLUMEFREESIZE 5 CString GetDriverInfomation(BYTE bAlpha,int iGTI_TYPE) { CString strResult = _T("");
以上就是关于C语言怎么获取硬件信息【网卡序号。。。】全部的内容,包括:C语言怎么获取硬件信息【网卡序号。。。】、VC怎么获取硬件ID,CPU,硬件,网卡等、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)