c++获取系统pcm_C/C++通过WMI和系统API函数获取获取系统硬件配置信息(转)

这段代码展示了如何使用C++通过WMI(Windows Management Instrumentation)和系统API来获取操作系统的版本信息,包括Windows版本、服务包、处理器类型和系统内存等。此外,还包含了检测是否为64位系统和获取CPU信息的函数。
摘要由CSDN通过智能技术生成

#include "StdAfx.h"#include"GetSysInfo.h"#include"float.h"#include"winperf.h"GetSysInfo::GetSysInfo(void)

{

}

GetSysInfo::~GetSysInfo(void)

{

}void GetSysInfo::GetOSVersion(CString &strOSVersion,CString &strServiceVersion)

{

CString str;

OSVERSIONINFOEX osvi;

SYSTEM_INFO si;

BOOL bOsVersionInfoEx;

ZeroMemory(&si, sizeof(SYSTEM_INFO));

ZeroMemory(&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("Windows Vista"));

}else{

str.Format(_T("Windows Server \"Longhorn\""));

}

}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)

{if( GetSystemMetrics(SM_SERVERR2) )

{

str.Format(_T("Microsoft Windows Server 2003 \"R2\""));

}else if( osvi.wProductType == VER_NT_WORKSTATION &&si.wProcessorArchitecture==PROCESSOR_ARCHITECTURE_AMD64)

{

str.Format(_T("Microsoft Windows XP Professional x64 Edition"));

}else{

str.Format(_T("Microsoft Windows Server 2003,"));

}

}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)

{

str.Format(_T("Microsoft Windows XP"));

}if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)

str.Format(_T("Microsoft Windows 2000"));if ( osvi.dwMajorVersion <= 4)

{

str.Format(_T("Microsoft Windows NT"));

}//Test for specific product on Windows NT 4.0 SP6 and later.

if( bOsVersionInfoEx )

{//将Service Pack 版本保存

strServiceVersion.Format(_T("Service Pack %d"),osvi.wServicePackMajor);//Test for the workstation type.

if ( osvi.wProductType == VER_NT_WORKSTATION &&si.wProcessorArchitecture!=PROCESSOR_ARCHITECTURE_AMD64)

{if( osvi.dwMajorVersion == 4)

str= str + _T("Workstation 4.0");else if( osvi.wSuiteMask &VER_SUITE_PERSONAL )

str= str + _T("Home Edition");else str = str + _T( "Professional");

}//Test for the server type.

else if ( 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_DATACENTER )

str= str + _T("Datacenter Edition for Itanium-based Systems");else if( osvi.wSuiteMask &VER_SUITE_ENTERPRISE )

str= str + _T("Enterprise Edition for Itanium-based Systems");

}else if ( si.wProcessorArchitecture ==PROCESSOR_ARCHITECTURE_AMD64 )

{if( osvi.wSuiteMask &VER_SUITE_DATACENTER )

str= str + _T( "Datacenter x64 Edition");else if( osvi.wSuiteMask &VER_SUITE_ENTERPRISE )

str= str + _T( "Enterprise x64 Edition");else str = str + _T( "Standard x64 Edition");

}else{if( osvi.wSuiteMask &VER_SUITE_DATACENTER )

str= str + _T( "Datacenter Edition");else if( osvi.wSuiteMask &VER_SUITE_ENTERPRISE )

str= str + _T( "Enterprise Edition");else if ( osvi.wSuiteMask &

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值