CC通过WMI和系统API函数获取获取系统硬件配置信息转Word格式文档下载.docx
《CC通过WMI和系统API函数获取获取系统硬件配置信息转Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《CC通过WMI和系统API函数获取获取系统硬件配置信息转Word格式文档下载.docx(6页珍藏版)》请在冰豆网上搜索。
链接库文件:
dsprov.dll
命名空间:
root\directory\ldap
作用:
将ActiveDirectory对象映射到WMI。
2.事件日志提供程序
ntevt.dll
root\cimv2
管理Windows事件日志,例如,读取、备份、清除、复制、删除、监视、重命名、压缩、解压缩和更改事件日志设置。
3.注册表提供程序
stdprov.dll
root\default
读取、写入、枚举、监视、创建、删除注册表项和值。
4.Win32提供程序
cimwin32.dll
提供关于计算机、磁盘、外围设备、文件、文件夹、文件系统、网络组件、操作系统、打印机、进程、安全性、服务、共享、SAM用户及组,以及更多资源的信息。
5.Windows安装程序提供程序
msiprov.dll
提供对已安装软件信息的访问。
以上可以看出WMI中的类被分组到不同的命名空间中,所以我们在调用相应的程序库时要注意引入对应的命名空间~~~我们今天用到的库就是cimwin32.dll库(第4个)。
好,废话到此为止,还有不懂的自己下去慢慢研究:
现在看代码...
一、基于API方式的实现代码,简单的对部分API函数的封装:
1、GetSysInfo.h文件
pragmaonce#include&
lt;
afxtempl.h&
classGetSysInfo
{
public:
GetSysInfo(void);
~GetSysInfo(void);
/********获取操作系统版本,Servicepack版本、系统类型************/
voidGetOSVersion(CString&
amp;
strOSVersion,CString&
strServiceVersion);
BOOLIsWow64();
//判断是否为64位操作系统/***********获取网卡数目和名字***********/
intGetInterFaceCount();
voidGetInterFaceName(CString&
InterfaceName,intpNum);
/***获取物理内存和虚拟内存大小***/
voidGetMemoryInfo(CString&
dwTotalPhys,CString&
dwTotalVirtual);
/****获取CPU名称、内核数目、主频*******/
voidGetCpuInfo(CString&
chProcessorName,CString&
chProcessorType,DWORD&
dwNum,DWORD&
dwMaxClockSpeed);
/****获取硬盘信息****/
voidGetDiskInfo(DWORD&
dwNum,CStringchDriveInfo[]);
/****获取显卡信息*****/
voidGetDisplayCardInfo(DWORD&
dwNum,CStringchCardName[]);
private:
CStringListInterfaces;
//保存所有网卡的名字
CList&
DWORD,DWORD&
&
Bandwidths;
//各网卡的带宽
TotalTraffics;
//各网卡的总流量
};
2.GetSysInfo.cpp文件
#include"
StdAfx.h"
GetSysInfo.h"
float.h"
winperf.h"
GetSysInfo:
:
GetSysInfo(void)
{
}
~GetSysInfo(void)
voidGetSysInfo:
GetOSVersion(CString&
strServiceVersion)
CStringstr;
OSVERSIONINFOEXosvi;
SYSTEM_INFOsi;
BOOLbOsVersionInfoEx;
ZeroMemory(&
si,sizeof(SYSTEM_INFO));
osvi,sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFOEX);
if(!
(bOsVersionInfoEx=GetVersionEx((OSVERSIONINFO*)&
osvi)))
{
osvi.dwOSVersionInfoSize=sizeof(OSVERSIONINFO);
GetVersionEx((OSVERSIONINFO*)&
osvi);
}
GetProcAddress(GetModuleHandle(TEXT("
kernel32.dll"
)),
"
GetNativeSystemInfo"
);
GetSystemInfo(&
si);
switch(osvi.dwPlatformId)
caseVER_PLATFORM_WIN32_NT:
if(osvi.dwMajorVersion==6&
osvi.dwMinorVersion==0)
if(osvi.wProductType==VER_NT_WORKSTATION)
str.Format(_T("
WindowsVista"
));
else
WindowsServer\"
Longhorn\"
if(osvi.dwMajorVersion==5&
osvi.dwMinorVersion==2)
if(GetSystemMetrics(SM_SERVERR2))
MicrosoftWindowsServer2003\"
R2\"
elseif(osvi.wProductType==VER_NT_WORKSTATION&
si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)
MicrosoftWindowsXPProfessionalx64Edition"
MicrosoftWindowsServer2003,"
osvi.dwMinorVersion==1)
MicrosoftWindowsXP"
MicrosoftWindows2000"
if(osvi.dwMajorVersion&
=4)
MicrosoftWindowsNT"
//TestforspecificproductonWindowsNT4.0SP6andlater.
if(bOsVersionInfoEx)
//将ServicePack版本保存
strServiceVersion.Format(_T("
ServicePack%d"
),osvi.wServicePackMajor);
//Testfortheworkstationtype.
if(osvi.wProductType==VER_NT_WORKSTATION&
si.wProcessorArchitecture!
=PROCESSOR_ARCHITECTURE_AMD64)
if(osvi.dwMajorVersion==4)
str=str+_T("
Workstation4.0"
elseif(osvi.wSuiteMask&
VER_SUITE_PERSONAL)
HomeEdition"
elsestr=str+_T("
Professional"
//Testfortheservertype.
elseif(osvi.wProductType==VER_NT_SERVER||
osvi.wProductType==VER_NT_DOMAIN_CONTROLLER)
if(osvi.dwMajorVersion==5&
osvi.dwMinorVersion==2)
if(si.wProcessorArchitecture==
PROCESSOR_ARCHITECTURE_IA64)
if(osvi.wSuiteMask&
VER_SUITE_D