/*------------------------------以下为头文件声明-------------------------*/
#include <Windows.h>
#include <string>
#include <iostream>
#include <winnt.h>
#include <tchar.h>
#include <IPHlpApi.h>
#pragma comment(lib,"ws2_32.lib")
#pragma comment(lib,"Advapi32.lib")
#pragma comment(lib, "Iphlpapi.lib")
using namespace std;
// ***** global macros ***** //
#define GBYTES 1073741824
#define MBYTES 1048576
#define KBYTES 1024
#define DKBYTES 1024.0
class CSysInfo
{
public:
CSysInfo();
~CSysInfo();
public:
const std::string GetOSVersion();
void SafeGetNativeSystemInfo(LPSYSTEM_INFO lpSystemInfo);
const std::string GetCPUInfo();
const std::string GetMemoryStatus();
void GetNetCardAndIPInfo(std::string &adapter_info, std::string &MAC_address, std::string &IP);
const std::string GetComputerUserName();
BOOL GetHardDiskInfo(LPTSTR pModelNo, LPTSTR pSerialNo);
void ToLittleEndian(PUSHORT pWords, int nFirstIndex, int nLastIndex, LPTSTR pBuf);
};
/*---------------------------------以下为类的功能实现-------------------------------*/
#include "SysInfo.h"
CSysInfo::CSysInfo()
{
}
CSysInfo::~CSysInfo()
{
}
const std::string CSysInfo::GetOSVersion()
{
std::string os_version("");
SYSTEM_INFO system_info;
memset(&system_info, 0, sizeof(SYSTEM_INFO));
GetSystemInfo(&system_info);
OSVERSIONINFOEX os;
os.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if (GetVersionEx((OSVERSIONINFO *)&os))
{
switch (os.dwMajorVersion) {
case 4:
//1996年7月发布
switch (os.dwMinorVersion) {
case 0:
if (os.dwPlatformId == VER_PLATFORM_WIN32_NT)
os_version = "Microsoft Windows NT 4.0 ";
else if (os.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
os_version = "Microsoft Windows 95 ";
break;
case 10:
os_version = "Microsoft Windows 98 ";
break;
case 90:
os_version = "Microsoft Windows Me ";
break;
}
break;
case 5:
switch (os.dwMinorVersion) {
//1999年12月发布
case 0:
os_version = "Microsoft Windows 2000 ";
if (os.wSuiteMask == VER_SUITE_ENTERPRISE)
os_version.append("Advanced Server ");
break;
//2001年8月发布
case 1:
os_version = "Microsoft Windows XP ";
if (os.wSuiteMask == VER_SUITE_EMBEDDEDNT)
os_version.append("Embedded ");
&n

本文介绍了一个C++类CSysInfo,用于在Windows环境下获取系统信息,包括操作系统版本、CPU信息、内存状态、网卡及IP信息、用户名和硬盘信息。通过调用Windows API和注册表读取,该类提供了丰富的系统监测功能。
359

被折叠的 条评论
为什么被折叠?



