C++ Windows通过注册表获取硬件信息

  • R0_901580
    了解作者
  • 1.6KB
    文件大小
  • 7z
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-07 12:33
    上传日期
C++ Windows通过注册表获取硬件信息 注:通过注册表获取
Screenfetch.7z
  • screenfetch.cpp
    2.5KB
  • main.cpp
    1.6KB
  • screenfetch.h
    465B
内容介绍
#include "screenfetch.h" #include <iostream> #include <windows.h> #include <string> #include <ctime> typedef void(WINAPI* FunctionGlobalMemoryStatusEx)(LPMEMORYSTATUS);//声明函数原型指针 #pragma warning(disable: 4996) // avoid GetVersionEx to be warned static const int kMaxInfoBuffer = 256; #define GBYTES 1073741824 #define MBYTES 1048576 #define KBYTES 1024 #define DKBYTES 1024.0 using namespace std; screenfetch::screenfetch() { //ctor } screenfetch::~screenfetch() { //remove("C://systeminfo.txt"); //dtor } void screenfetch::showosversion(void) { OSVERSIONINFO osver = {sizeof(OSVERSIONINFO)}; GetVersionEx(&osver); cout << osver.dwMajorVersion << "." << osver.dwMinorVersion; } string screenfetch::getos(void) { OSVERSIONINFO osver = {sizeof(OSVERSIONINFO)}; GetVersionEx(&osver); string os_name; if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 0) os_name = "Windows 2000"; else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 1) os_name = "Windows XP"; else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 0) os_name = "Windows 2003"; else if (osver.dwMajorVersion == 5 && osver.dwMinorVersion == 2) os_name = "windows vista"; else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 1) os_name = "windows 7"; else if (osver.dwMajorVersion == 6 && osver.dwMinorVersion == 2) os_name = "windows 10"; return os_name; } void screenfetch::showtime(void) { time_t tt = time(NULL); tm* time= localtime(&tt); cout << time->tm_year + 1900 << "-" << time->tm_mon + 1 << "-" << time->tm_mday; } void screenfetch::showram(void) { MEMORYSTATUS ms; //记录内容空间信息的结构体变量 GlobalMemoryStatus(&ms);//调用GlobalMemoryStatus()函数获取内存信息 cout << (float)(ms.dwTotalPhys - ms.dwAvailPhys) / 1024 / 1024 << " / " <<(float)ms.dwTotalPhys / 1024 / 1024 << "MB"; //已用物理内存大小 } string screenfetch::getcpu(void) { string cpuname; HKEY cpuinfo; char _cpuinfo[255]; DWORD size; if(ERROR_SUCCESS==RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0", 0, KEY_READ, &cpuinfo)) { RegQueryValueEx(cpuinfo, "ProcessorNameString", NULL, NULL, (BYTE*)_cpuinfo, &size); cpuname = (string)_cpuinfo; } RegCloseKey(cpuinfo); return cpuname; }
评论
    相关推荐