一、头文件如下:
#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); };
二、cpp如下:
#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; //