《C++检测电脑配置信息》由会员分享,可在线阅读,更多相关《C++检测电脑配置信息(12页珍藏版)》请在金锄头文库上搜索。
1、C+检测电脑配置信息真检测内存空间/获取物理内存和虎拟内存大小*/Void GetMemorylnfo(CString & d wTot a IP hy s, CSt r i n g & dwTotalVirtual);/ TODO:Add extra initializatio n hereMEMORYSTATUS Mem;/ get the memory statusGlobalMemoryStatus(&Mem);DWORD dwSize = (DWORD)Mem.dwTotalPhys/(1024*1024);DWORD dwVirtSize = (DWORD)Mem.dwTotalV
2、irtual/(1024*1024);dwTotalPhys.FormatLT(H物理内存:ld MBH),dwSize);d wlota I Vi rtu a I. For m at(_T (虚拟内存:ld MBn),dwVirtSize);2、检测CPU型号/*获取CPU名称、内核数目、主频*/VoidGetCpulnfo(CString &chProcessorNameXString &chProcessorType,DWORD&dwNum,DWORD &dwMaxClockSpeed)CString strPath=JTHARDWAREDESCRIPTIONSystemCentralP
3、rocessor(r);注 册表 子键路径CRegKey regkey;定义注册表类对象LONG IResult;/LONG型变量一反应结果IResult=regkey.Open(HKEY-LOCAL_MACHINE,LPCTSTR(strPath),KEY_ALL_ACCESS); 打开注 册表键if (IResult!二ERROR_SUCCESS)return;WCHAR chCPUName50 = 0;DWORD dwSize=50;获取 ProcessorNameString 字段值if(ERROR_SUCCESS= regkey.QueryStringValue(_T(,Proces
4、sorNameString,)/chCPUName/&dwSize) chProcessorName = chCPUName;查询CPU主频DWORD dwValue;if (ERROR_SUCCESS = regkey.QueryDWORDValueLTfMHzwValue) dwMaxClockSpeed = dwValue;regkey.Close();/ 关闭注册表/UpdateData(FALSE);获取CPU核心数目SYSTEMNFO si;memset(&siQsizeof(SYSTEM JNFO);GetSystemlnfo(&si);dwNum = si.dwNumberOf
5、Processors;switch (si.dwProcessorType)case PROCESSOR_INTEL_386:chProcessorType.Format(_T(,llntel 386 processor1);break;case PROCESSOR_INTEL_486:chProcessorType.Format(_T(,llntel 486 Processor1);break;case PROCESSOR_INTEL_PENTIUM:chProcessorType.Format(_T(,llntel Pentium Processor);break;case PROCESS
6、ORJNTELJA64:chProcessorType.Format(_T(,llntel IA64 Processor);break;case PROCESSOR AMD X8664:chProcessorType.FormatLTCAMD X8664 Processor11); break;default:chProcessorIype.FormatLT(未知);break;3、检测硬盘信息获取硕盘信息*/void GetDisklnfo(DWORD &dwNum,CStnng chDrivelnfo)DWORD DiskCount = 0;利用GetLogicalDrivesf)函数可以
7、获取系统中逻辑驱动器的数量,函数返回的是一个位 无符号整型数据。DWORD Diskinfo = GetLogicalDrives();通过循坏操作查看每一位数据是否为,如果为则磁盘为真,如果为则磁盘不存在。while(Disklnfo)通过位运算的逻辑与操作,判断是否为Sleep(lO);if(Disklnfo&1)DiskCount+;Diskinfo = Diskinfo 1;/通过位运算的右移操作保证每循环一次所检查的位置向右 移动一位。*/if (dwNum DiskCount)return;/实际的磁盘数目人于dwNumdwNum = DiskCount;/将磁盘分区数量保存/通过
8、GetLogicalDriveStrings()函数获取所有驱动器字符串信息长度int DSLength = GetLogicalDriveStrings(0,NULL);WCHAR* DStr = new WCHARDSLength;memset(DStr,0,DSLength);通过GetLogicalDriveStrings将字符串信息复制到堆区数组中,其中保存了所有驱动器 的信息。GetLogicalDriveStrings(DSLengthzDStr);int DType;int si=O;BOOLfResult;unsigned J nt 64 i64FreeBytesToCall
9、er;unsigned J nt64 i64Total Bytes;unsigned _int64 i64FreeBytes;读取各驱动器信息,由于DStr内部数据格式是A:NULLB:NULLC:NULL,所以 DSLength/4可以获得具体大循坏范围for(int i=0;iDSLength/4;+i)Sleep(lO);CString strdriver = DStr+i*4;CString strTmp,strTota I Bytes,st汗reeBytes;DType = GetDriveType(strdriver);/GetDriveType 函数,町以获取驱动器类型,参数 为
10、驱动器的根目录switch (DType)case DRIVE_FIXED:strTmp.FormatLTC 本地磁盘”);break;case DRIVE_CDROM:strTmp.FormatLTCDVD 驱动器”);break;case DRIVE_REMOVABLE:strTmpFormat(_T可移动磁盘);break;case DRIVE_REMOTE:strTmp.Format(_T(网络磁盘);break;caseDRIVE_RAMDISK: strTmp.FormatLT(虚拟 RAM 磁盘f,);break;case DRIVE UNKNOWN:strTmp.FormatL
11、T(虚拟 RAM 未知设备”);break;default:strTmp.FormatLTC未知设备);break;/GetDiskFreeSpaceEx函数,可以获取驱动器磁盘的空间状态,函数返回的是个 BOOL类型数据fResult = GetDiskFreeSpaceEx (strdrivec(PULARGEJNTEGER)&i64FreeBytesToCaller, (PULARGEJNTEGER)&i64TotalBytesz(PULARGEJNTEGER)&i64FreeBytes);if(fResult)strTotalBytes.Format(_T(磁盘总容量 %fMB,)J(
12、float)i64TotalBytes/1024/1024); strFreeBytes.Format(_T(磁盘剩余空|uj %fMB,)/(float)i64FreeBytesToCaller/1024/1024);elsestrTotalBytesFormat(_T();strF reeBytes.Format(_T(,H);chDrivelnfoi = strTmp + _T(T) + strdriver + _T(+ strTotal Bytes + strFreeBytes;si+=4;4、检测显卡信息/*获取显卡信息*/void GetDisplayCardlnfo(DWORD
13、&dwNum,CString chCardName)HKEY keyServ;HKEY keyEnum;HKEY key;HKEY key2;LONG IResult;/LONG型变量一保存函数返回值查询SYSTEMCurrentControlSetServices下的所有子键保存至IkeyServIResult=RegOpenKeyExWKEYLOCALMACHINE/rEXTCSYSTEMWCurrentControlSetWServicesJOKEYRE AD,&keyServ);if (ERROR_SUCCESS != IResult)return;查ifiJ,SYSTEMCurren
14、tControlSetEnum,1 卜的所有子键保存到 keyEnumIResult=RegOpenKeyEx(HKEY_LOCAL_MACHINEzTEXT(,ISYSTEMCurrentControlSetEnum,)/OzKEY_READ, &keyEnum);if (ERROR_SUCCESS != IResult)return;int i = 0,count = 0;DWORD size = 0,type = 0;for (;+i)Sleep(5);size = 512;TCHAR name512 = 0;/保存keyServ F各子项的字段名称逐个枚举keyServ下的各子项字段保存到name中IResult = RegEnumKeyEx(keyServ丄 name,&size,NULL, NULL, NULL,NULL);要读取的子项不存在,即keyServ的子项全部遍历完时跳出循坏if(lResult = ERROR_NO_MORE .ITEMS)break;打开keyServ的子项字段为name所标识的