C/C++获取CPU等硬件信息&&屏幕截图

打算练习Socket的时候用用,最近有点小事情,没时间继续完善,先把写的这些代码贴上来,有空了再完善一下。

HardwareInfo.h

  1 #include <stdio.h>
  2 #include <windows.h>
  3 #include <vfw.h>
  4
  5 #pragma comment(lib,"Vfw32.lib")
  6 #pragma comment(lib,"winmm.lib")
  7 #ifndef VER_NT_WORKSTATION
  8 #define VER_NT_WORKSTATION 1
  9 #endif
 10
 11 /*
 12     // vc6.0需定义
 13 typedef struct _MEMORYSTATUSEX {
 14     DWORD dwLength;                        // 结构体数据大小 sizeof(_MEMORYSTATUSEX)
 15     DWORD dwMemoryLoad;                    // 内存使用率
 16     LONGLONG ullTotalPhys;                    // 物理内存总大小(单位:字节)
 17     LONGLONG ullAvailPhys;                    // 物理内存可用大小(单位:字节)
 18     LONGLONG ullTotalPageFile;                // 总页面大小(物理内存总大小+硬盘划分的虚拟内存总大小)(单位:字节)
 19     LONGLONG ullAvailPageFile;                // 当前进程能获取的最大内存数(单位:字节)
 20     LONGLONG ullTotalVirtual;                // 当前进程最大内存寻址地址(默认2GB,开启大地址后就是4GB)
 21     LONGLONG ullAvailVirtual;                // 当前进程可用最大内存(单位:字节)
 22     LONGLONG ullAvailExtendedVirtual;
 23 } MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
 24 */
 25 typedef struct _OSVERSIONINFOEXA1 {
 26     DWORD dwOSVersionInfoSize;
 27     DWORD dwMajorVersion;
 28     DWORD dwMinorVersion;
 29     DWORD dwBuildNumber;
 30     DWORD dwPlatformId;
 31     CHAR  szCSDVersion[128];
 32     WORD  wServicePackMajor;
 33     WORD  wServicePackMinor;
 34     WORD  wSuiteMask;
 35     BYTE  wProductType;
 36     BYTE  wReserved;
 37 } OSVERSIONINFOEXA1, *POSVERSIONINFOEXA1, *LPOSVERSIONINFOEXA1;
 38
 39
 40 /*
 41     屏幕截图
 42     lpData:存放截图数据指针
 43     hWnd  :目标窗口,默认为桌面
 44     成功返回截图数据大小,失败返回0.
 45 */
 46 DWORD PrtScr(PCHAR *lpData, HWND hWnd = 0);
 47
 48 /*
 49     是否有摄像头
 50     有摄像头返回TRUE,否则返回FALSE
 51 */
 52 BOOL HaveCameras(void);
 53
 54 /*
 55     获取CPU名称
 56     成功返回CPU名称,失败返回NULL(VS2013不支持Debug模式下获取)
 57 */
 58 LPSTR GetCPUName(void);
 59
 60 /*
 61     获取CPU制造商
 62     成功返回CPU制造商,失败返回NULL(VS2013不支持Debug模式下获取)
 63 */
 64 LPSTR GetCPUManufacturer(void);
 65
 66 /*
 67     获取声卡名字
 68     成功返回声卡名字,失败返回NULL
 69 */
 70 LPSTR GetSoundCarName(void);
 71
 72 /*
 73     获取磁盘容量信息
 74     diskPath:盘符
 75     used:已用空间
 76     freed:剩余空间
 77     total:总空间
 78     成功返回TRUE,失败返回FALSE
 79 */
 80 BOOL GetDiskSpaceInfo(LPSTR diskPath, float *used, float *freed, float *total);
 81
 82 /*
 83     获取运行内存总额
 84     返回运存总额
 85 */
 86 FLOAT GetSysRam(void);
 87
 88 /*
 89     获取运存已用比例
 90     返回运存已用比例
 91 */
 92 DWORD GetRamProportion(void);
 93
 94 /*
 95     获取系统启动时间
 96     返回格式化文本字符串
 97 */
 98 LPSTR GetSysStartTime(void);
 99
100 /*
101     获取系统信息
102     dwMajor:高版本位
103     dwMinjor:低版本位
104     bDesc:是否获取系统描述
105     bBit:是否获取位数
106     bSPVer:是否获取系统补丁包版本
107     bBuildVer:是否获取内部版本
108     成功返回系统信息字符串,失败返回NULL
109 */
110 LPSTR GetSysInfo(DWORD *dwMajor = NULL, DWORD *dwMinjor = NULL, BOOL bDesc = FALSE, BOOL bBit = FALSE, BOOL bSPVer = FALSE, BOOL bBuildVer = FALSE);

HardwareInfo.cpp

  1 #include "HardwareInfo.h"
  2
  3 int main(void)
  4 {
  5
  6     LPSTR lpCPUName = GetCPUName();
  7     LPSTR lpCPUManu = GetCPUManufacturer();
  8     LPSTR lpSoundCarName = GetSoundCarName();
  9     printf("处理器: %s\n\n", lpCPUName);
 10     printf("CPU制造商: %s\n\n", lpCPUManu);
 11     printf("声卡: %s\n\n", lpSoundCarName);
 12     float used, usable, total;
 13     GetDiskSpaceInfo("D:", &used, &usable, &total);
 14     printf("D盘 已用: %.1fG, 可用:%.1fG, 总大小:%.1fG\n\n", used, usable, total);
 15     printf("运行内存: %.1fG, 已用%d%%\n\n", GetSysRam(), GetRamProportion());
 16     LPSTR lpStartTime = GetSysStartTime();
 17     printf("已开机:  %s\n\n", GetSysStartTime());
 18     LPSTR lpSysVer = GetSysInfo(0, 0, 1, 1, 1);
 19     printf("系统版本: %s\n\n", lpSysVer);
 20     free(lpCPUName);
 21     free(lpCPUManu);
 22     free(lpSoundCarName);
 23     free(lpStartTime);
 24     free(lpSysVer);
 25
 26     Sleep(1000);
 27     DWORD dwLen = 0;
 28     char *lpData = NULL;
 29
 30     dwLen = PrtScr(&lpData);
 31     FILE *wj = NULL;
 32     fopen_s(&wj, "c:\\1.bmp", "wb");
 33     fwrite(lpData, dwLen, 1, wj);
 34     fclose(wj);
 35     free(lpData);
 36     system("c:\\1.bmp");
 37     system("pause");
 38     return 0;
 39 }
 40
 41 DWORD PrtScr(PCHAR *lpData, HWND hWnd)
 42 {
 43     HDC hdcScreen, hdcMem;
 44     RECT rc = { 0 }, desRc = { 0 };
 45     HBITMAP hbmScreen = NULL;
 46     BITMAP bmpScreen = { 0 };
 47     BITMAPINFOHEADER bitInfo = { 0 };
 48     BITMAPFILEHEADER bitHead = { 0 };
 49     DWORD dwBmpSize, dwSizeofDIB;
 50     char *lpbitmap = NULL;
 51     int width, height;
 52
 53     if (!hWnd)
 54         hWnd = GetDesktopWindow();
 55     GetWindowRect(hWnd, &rc);
 56     GetWindowRect(GetDesktopWindow(), &desRc);
 57
 58     hdcScreen = GetDC(NULL);
 59     hdcMem = CreateCompatibleDC(hdcScreen);
 60     if (!hdcMem)
 61         return 0;
 62     hbmScreen = CreateCompatibleBitmap(hdcScreen, rc.right - rc.left, rc.bottom - rc.top);
 63     if (!hbmScreen)
 64         return 0;
 65     SelectObject(hdcMem, hbmScreen);
 66     width = (rc.right > desRc.right) ? (desRc.right - rc.left) : (rc.right - rc.left);
 67     height = (rc.bottom > desRc.bottom) ? (desRc.bottom - rc.top) : (rc.bottom - rc.top);
 68     if (!BitBlt(hdcMem, 0, 0, width, height, hdcScreen, rc.left, rc.top, SRCCOPY))
 69         return 0;
 70     GetObject(hbmScreen, sizeof(BITMAP), &bmpScreen);
 71
 72     bitInfo.biSize = sizeof(BITMAPINFOHEADER);
 73     bitInfo.biWidth = width;
 74     bitInfo.biHeight = height;
 75     bitInfo.biPlanes = 1;
 76     bitInfo.biBitCount = 32;
 77     bitInfo.biCompression = BI_RGB;
 78
 79     dwBmpSize = ((bmpScreen.bmWidth * bitInfo.biBitCount + 31) / 32) * 4 * bmpScreen.bmHeight;
 80     lpbitmap = (char *)malloc(dwBmpSize);
 81     if (!lpbitmap)
 82         return 0;
 83     GetDIBits(hdcScreen, hbmScreen, 0, (UINT)bmpScreen.bmHeight, lpbitmap, (BITMAPINFO *)&bitInfo, DIB_RGB_COLORS);
 84
 85     dwSizeofDIB = dwBmpSize + sizeof(bitHead)+sizeof(bitInfo);
 86     bitHead.bfOffBits = (DWORD)sizeof(bitHead)+(DWORD)sizeof(bitInfo);
 87     bitHead.bfSize = dwSizeofDIB;
 88     // 必须是字符BM或者十六进制代替0x4D42="BM"
 89     bitHead.bfType = MAKEWORD(‘B‘, ‘M‘);
 90
 91     *lpData = (char *)malloc(dwSizeofDIB);
 92     if (!*lpData)
 93         return 0;
 94     memmove(*lpData, &bitHead, sizeof(bitHead));
 95     memmove(*lpData + sizeof(bitHead), &bitInfo, sizeof(bitInfo));
 96     memmove(*lpData + sizeof(bitHead)+sizeof(bitInfo), lpbitmap, dwBmpSize);
 97     free(lpbitmap);
 98     DeleteObject(hbmScreen);
 99     DeleteObject(hdcMem);
100     ReleaseDC(NULL, hdcScreen);
101     return dwSizeofDIB;
102 }
103
104 BOOL HaveCameras(void)
105 {
106     char ver[256] = { 0 }, name[256] = { 0 };
107     UINT num = 0;
108
109     do
110     {
111         memset(name, 0, 256);
112         if (capGetDriverDescription(num, name, 100, ver, 100))
113         {
114             num++;
115         }
116     } while (lstrlen(name));
117     return (num ? TRUE : FALSE);
118 }
119
120 LPSTR GetCPUName(void)
121 {
122     LPSTR lpName = (LPSTR)malloc(100);
123     memset(lpName, 0, 100);
124
125     __asm{
126         PUSHAD
127             MOV EAX, 0x80000002
128             CPUID
129             MOV ESI, [EBP - 0x4]
130             MOV SS : [ESI], EAX
131             MOV SS : [ESI + 0x4], EBX
132             MOV SS : [ESI + 0x8], ECX
133             MOV SS : [ESI + 0xC], EDX
134             MOV EAX, 0x80000003
135             CPUID
136             MOV SS : [ESI + 0x10], EAX
137             MOV SS : [ESI + 0x14], EBX
138             MOV SS : [ESI + 0x18], ECX
139             MOV SS : [ESI + 0x1C], EDX
140             MOV EAX, 0x80000004
141             CPUID
142             MOV SS : [ESI + 0x20], EAX
143             MOV SS : [ESI + 0x24], EBX
144             MOV SS : [ESI + 0x28], ECX
145             MOV SS : [ESI + 0x2C], EDX
146             POPAD
147     }
148     return lpName;
149 }
150
151 LPSTR GetCPUManufacturer(void)
152 {
153     LPSTR lpStr = (LPSTR)malloc(20);
154     memset(lpStr, 0, 20);
155
156     __asm{
157         PUSHAD
158             XOR EAX, EAX
159             CPUID
160             MOV EAX, DWORD PTR SS : [EBP - 0x4]
161             MOV DWORD PTR SS : [EAX], EBX
162             MOV DWORD PTR SS : [EAX + 0x4], EDX
163             MOV DWORD PTR SS : [EAX + 0x8], ECX
164             POPAD
165     }
166
167     if (!lstrcmp("GenuineIntel", lpStr))
168         memmove(lpStr, "Intel Corporation.", 20);
169     else if (!lstrcmp("AuthenticAMD", lpStr))
170         memmove(lpStr, "Advanced Micro Devices.", 20);
171     else if (!lstrcmp("AMD ISBETTER", lpStr))
172         memmove(lpStr, "Advanced Micro Devices.", 20);
173     else if (!lstrcmp("Geode By NSC", lpStr))
174         memmove(lpStr, "National Semiconductor.", 20);
175     else if (!lstrcmp("CyrixInstead", lpStr))
176         memmove(lpStr, "Cyrix Corp., VIA Inc.", 20);
177     else if (!lstrcmp("NexGenDriven", lpStr))
178         memmove(lpStr, "NexGen Inc., Advanced Micro Devices.", 20);
179     else if (!lstrcmp("CentaurHauls", lpStr))
180         memmove(lpStr, "IDT\\Centaur, Via Inc.", 20);
181     else if (!lstrcmp("UMC UMC UMC ", lpStr))
182         memmove(lpStr, "United Microelectronics Corp.", 20);
183     else if (!lstrcmp("RiseRiseRise", lpStr))
184         memmove(lpStr, "Rise.", 20);
185     else if (!lstrcmp("GenuineTMx86", lpStr))
186         memmove(lpStr, "Transmeta.", 20);
187     else if (!lstrcmp("TransmetaCPU", lpStr))
188         memmove(lpStr, "Transmeta.", 20);
189     else
190         memmove(lpStr, "Unknown Manufacturer.", 20);
191
192     return lpStr;
193 }
194
195 LPSTR GetSoundCarName(void)
196 {
197     WAVEOUTCAPS wav = { 0 };
198     LPSTR lpName = (LPSTR)malloc(50);
199
200     waveOutGetDevCaps(0, &wav, sizeof(wav));
201
202     // 有点电脑获取的数据不完整,缺失 " Audio)",为了美观获取不到的手动加入
203     if (wav.szPname[lstrlen(wav.szPname)-1] != ‘)‘)
204         sprintf_s(lpName, 50, "%s Audio)", wav.szPname);
205     else
206         sprintf_s(lpName, 50, "%s", wav.szPname);
207     return lpName;
208 }
209
210 BOOL GetDiskSpaceInfo(LPSTR diskPath, float *used, float *freed, float *total)
211 {
212     ULARGE_INTEGER a1, b1, c1;
213     LONGLONG a, b, c;
214     float v1, v2, v3;
215     if (!GetDiskFreeSpaceEx(diskPath, &a1, &b1, &c1))
216         return FALSE;
217
218     a = (LONGLONG)a1.QuadPart;
219     b = (LONGLONG)b1.QuadPart;
220     c = (LONGLONG)c1.QuadPart;
221     c = b - a;
222
223     v1 = (float)(a / (1024 * 1024 * 1024.0));
224     v2 = (float)(b / (1024 * 1024 * 1024.0));
225     v3 = (float)(c / (1024 * 1024 * 1024.0));
226
227     memmove(used, &v3, sizeof(float));
228     memmove(freed, &v1, sizeof(float));
229     memmove(total, &v2, sizeof(float));
230
231     return TRUE;
232 }
233
234 FLOAT GetSysRam(void)
235 {
236     typedef BOOL(WINAPI *func)(LPMEMORYSTATUSEX);
237     MEMORYSTATUSEX stMem = { 0 };
238
239     func GlobalMemoryStatusEx = (func)GetProcAddress(LoadLibrary("Kernel32.dll"), "GlobalMemoryStatusEx");
240     stMem.dwLength = sizeof(stMem);
241     GlobalMemoryStatusEx(&stMem);
242     return (FLOAT)(stMem.ullTotalPhys / (1024 * 1024 * 1024.0));
243 }
244
245 DWORD GetRamProportion(void)
246 {
247     typedef BOOL(WINAPI *func)(LPMEMORYSTATUSEX);
248     MEMORYSTATUSEX stMem = { 0 };
249
250     func GlobalMemoryStatusEx = (func)GetProcAddress(LoadLibrary("Kernel32.dll"), "GlobalMemoryStatusEx");
251     stMem.dwLength = sizeof(stMem);
252     GlobalMemoryStatusEx(&stMem);
253     return stMem.dwMemoryLoad;
254 }
255
256 LPSTR GetSysStartTime(void)
257 {
258     LPSTR lpStr = (LPSTR)malloc(sizeof(char)* 50);
259     DWORD dwStart = GetTickCount();
260     DWORD day, hou, min, sec;
261
262     day = dwStart / (1000 * 60 * 60 * 24);
263     hou = dwStart / (1000 * 60 * 60) - day * 24;
264     min = dwStart / (1000 * 60) - day * 24 * 60 - hou * 60;
265     sec = dwStart / (1000) - day * 24 * 60 * 60 - hou * 60 * 60 - min * 60;
266
267     sprintf_s(lpStr, 50, "%d天%d小时%d分钟%d秒", day, hou, min, sec);
268     return lpStr;
269 }
270
271 LPSTR GetSysInfo(DWORD *dwMajor, DWORD *dwMinjor, BOOL bDesc, BOOL bBit, BOOL bSPVer, BOOL bBuildVer)
272 {
273     OSVERSIONINFOEXA1 osvi = { 0 };
274     SYSTEM_INFO si = { 0 };
275     BOOL bWow64 = FALSE;
276     DWORD dwType = 0, dwBuild = 0;
277     char strSys[100] = { 0 }, strVer[20] = { 0 };
278
279     osvi.dwOSVersionInfoSize = sizeof(osvi);
280     typedef BOOL(WINAPI *fun)(LPOSVERSIONINFOEXA1);
281     fun GetVersionEx1 = (fun)GetProcAddress(LoadLibrary("Kernel32.dll"), "GetVersionExA");
282     if (GetVersionEx1(&osvi))
283     {
284         dwBuild = osvi.dwBuildNumber;
285         GetSystemInfo(&si);
286
287         typedef BOOL(WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
288         LPFN_ISWOW64PROCESS IsWow64Process1 = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process");
289         IsWow64Process1((void *)-1, &bWow64);
290
291         typedef void (WINAPI *func)(DWORD *, DWORD *, DWORD *);
292         func RtlGetNtVersionNumbers = (func)GetProcAddress(LoadLibrary("ntdll.dll"), "RtlGetNtVersionNumbers");
293         RtlGetNtVersionNumbers(&osvi.dwMajorVersion, &osvi.dwMinorVersion, &osvi.dwBuildNumber);
294
295         if (dwMajor)
296             *dwMajor = osvi.dwMajorVersion;
297         if (dwMinjor)
298             *dwMinjor = osvi.dwMinorVersion;
299
300         if (osvi.dwMajorVersion == 10)
301         {
302             if (osvi.dwMinorVersion == 0)
303             {
304                 lstrcpyn(strSys, (osvi.wProductType == VER_NT_WORKSTATION ? "Windows 10" : "Windows Server 2016"), 100);
305             }
306         }
307         else if (osvi.dwMajorVersion == 6)
308         {
309             if (osvi.dwMinorVersion == 0)
310             {
311                 lstrcpyn(strSys, (osvi.wProductType == VER_NT_WORKSTATION ? "Windows Vista" : "Windows Server 2008"), 100);
312             }
313             else if (osvi.dwMinorVersion == 1)
314             {
315                 lstrcpyn(strSys, (osvi.wProductType == VER_NT_WORKSTATION ? "Windows 7" : "Windows Server 2008 R2"), 100);
316             }
317             else if (osvi.dwMinorVersion == 2)
318             {
319                 lstrcpyn(strSys, (osvi.wProductType == VER_NT_WORKSTATION ? "Windows 8" : "Windows Server 2012"), 100);
320             }
321             else if (osvi.dwMinorVersion == 3)
322             {
323                 lstrcpyn(strSys, (osvi.wProductType == VER_NT_WORKSTATION ? "Windows 8.1" : "Windows Server 2012 R2"), 100);
324             }
325         }
326         else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
327         {
328             lstrcpyn(strSys, "Windows 2000", 100);
329             if (osvi.wProductType == 1)
330             {
331                 lstrcpyn(strVer, "Professional", 20);
332             }
333             else if ((osvi.wSuiteMask & 128) == 0)
334             {
335                 lstrcpyn(strVer, "Datacenter Server", 20);
336             }
337             else if ((osvi.wSuiteMask & 2) == 0)
338             {
339                 lstrcpyn(strVer, "Advanced Server", 20);
340             }
341             else
342             {
343                 lstrcpyn(strVer, "Server", 20);
344             }
345         }
346         else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
347         {
348             lstrcpyn(strSys, "Windows XP", 100);
349             if ((osvi.wSuiteMask & 512) == 1)
350             {
351                 lstrcpyn(strVer, "Home Edition", 20);    // 家庭版
352             }
353             else
354             {
355                 lstrcpyn(strVer, "Professional", 20);    // 专业版
356             }
357         }
358         else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
359         {
360             if (GetSystemMetrics(89) != 0)
361             {
362                 lstrcpyn(strSys, "Windows Server 2003 R2, ", 100);
363             }
364             else if ((osvi.wSuiteMask & 8192) == 8192)
365             {
366                 lstrcpyn(strSys, "Windows Storage Server 2003", 100);
367             }
368             else if ((osvi.wSuiteMask & 32768) == 32768)
369             {
370                 lstrcpyn(strSys, "Windows Home Server", 100);
371             }
372             else if (osvi.wProductType == 1 && si.wProcessorArchitecture == 9)
373             {
374                 lstrcpyn(strSys, "Windows XP Professional x64 Edition", 100);    // XP专业版64位系统
375             }
376             else
377             {
378                 lstrcpyn(strSys, "Windows Server 2003, ", 100);
379             }
380         }
381         else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
382         {
383             lstrcpyn(strSys, "Windows 98", 100);
384         }
385         else if (osvi.dwMajorVersion >= 6)
386         {
387             typedef BOOL(WINAPI *pGetProductInfo)(DWORD, DWORD, DWORD, DWORD, PDWORD);
388             pGetProductInfo RtlGetProductInfo = (pGetProductInfo)GetProcAddress(LoadLibrary("Kernel32.dll"), "RtlGetProductInfo");
389             RtlGetProductInfo(osvi.dwMajorVersion, osvi.dwMinorVersion, 0, 0, &dwType);
390
391             switch (dwType)
392             {
393             case 1:    // 旗舰版
394                 lstrcpyn(strVer, "Ultimate Edition", 20);
395                 break;
396             case 2:    // 家庭普通版
397                 lstrcpyn(strVer, "Home Basic Edition", 20);
398                 break;
399             case 3:    // 家庭高级版
400                 lstrcpyn(strVer, "Home Premiu Edition", 20);
401                 break;
402             case 4:    // 企业版
403                 lstrcpyn(strVer, "Enterprise Edition", 20);
404                 break;
405             case 6:    // 商业版
406                 lstrcpyn(strVer, "Business Edition", 20);
407                 break;
408             case 7:    // 服务器标准版
409                 lstrcpyn(strVer, "Standard", 20);
410                 break;
411             case 8:    // 服务器企业版
412                 lstrcpyn(strVer, "Datacenter Edition", 20);
413                 break;
414             case 9:    // 小型服务器
415                 lstrcpyn(strVer, "Small Business Server", 20);
416                 break;
417             case 10:    // 服务器企业版(完整的安装)
418                 lstrcpyn(strVer, "Enterprise Edition", 20);
419                 break;
420             case 11:    // 入门版
421                 lstrcpyn(strVer, "Starter Edition", 20);
422                 break;
423             case 12:    // 服务器数据中心版(核心安装)
424                 lstrcpyn(strVer, "Datacenter Edition (core installation)", 20);
425                 break;
426             case 13:    // 服务器标准版(核心安装)
427                 lstrcpyn(strVer, "Standard Edition (core installation)", 20);
428                 break;
429             case 14:    // 服务器企业版(核心安装)
430                 lstrcpyn(strVer, "Enterprise Edition (core installation)", 20);
431                 break;
432             case 15:    // 一个企业级的平台
433                 lstrcpyn(strVer, "Enterprise Edition for Itanium-based Systems", 20);
434                 break;
435             case 16:    // 商用公司版
436                 lstrcpyn(strVer, "Business N", 20);
437                 break;
438             case 17:    // Web服务器(完整安装)
439                 lstrcpyn(strVer, "Web Server (full installation)", 20);
440                 break;
441             case 18:    // 服务器群集版
442                 lstrcpyn(strVer, "HPC Edition", 20);
443                 break;
444             case 19:    // 2008 R2 储存服务器版
445                 lstrcpyn(strVer, "Windows Storage Server 2008 R2 Essentials", 20);
446                 break;
447             case 20:    // 服务器快速储存版
448                 lstrcpyn(strVer, "Storage Server Express", 20);
449                 break;
450             case 21:    // 服务器标准储存版
451                 lstrcpyn(strVer, "Storage Server Standard", 20);
452                 break;
453             case 22:    // 服务器储存组
454                 lstrcpyn(strVer, "Storage Server Workgroup", 20);
455                 break;
456             case 23:    // 服务器储存企业版
457                 lstrcpyn(strVer, "Storage Server Enterprise", 20);
458                 break;
459             case 25:    // 小型商业服务器
460                 lstrcpyn(strVer, "Small Business Server Premium Edition", 20);
461                 break;
462             case 48:    // 专业版
463                 lstrcpyn(strVer, "Professional", 20);
464                 break;
465             }
466         }
467     }
468     if (lstrlen(strSys) < 2)
469     {
470         sprintf_s(strSys, 100, "获取失败,请检查版本:%d.%d", osvi.dwMajorVersion, osvi.dwMinorVersion);
471         return NULL;
472     }
473     else
474     {
475         LPSTR lpStr = (LPSTR)malloc(sizeof(char)* 100);
476
477         lstrcpyn(lpStr, strSys, lstrlenA(strSys) + 1);
478         if (bDesc)
479         {
480             lstrcatA(lpStr, " ");
481             lstrcatA(lpStr, strVer);
482         }
483         if (bBit)
484             lstrcatA(lpStr, (bWow64 ? " x64 " : " x86 "));
485         if (bSPVer)
486             lstrcatA(lpStr, (LPCSTR)&osvi.szCSDVersion);
487         if (bBuildVer)
488             sprintf_s(lpStr,100, "%s,Build:%d", lpStr, dwBuild);
489         return lpStr;
490     }
491     return NULL;
492 }

 效果图

原文地址:https://www.cnblogs.com/biaoge140/p/9749169.html

时间: 2024-10-07 22:31:10

C/C++获取CPU等硬件信息&&屏幕截图的相关文章

Android获取cpu和内存信息、网址的代码

android获取手机cpu并判断是单核还是多核 /** * Gets the number of cores available in this device, across all processors. * Requires: Ability to peruse the filesystem at "/sys/devices/system/cpu" * @return The number of cores, or 1 if failed to get result */ pri

C#获取当前主机硬件信息

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks; using System.Net;using System.Management;  //在项目->添加引用....里面引用System.Managementusing System.Runtime.InteropServices; namespace FileSplit{

PowerShell 获取系统的硬件信息

1.获取系统的BIOS的信息: Get-WMIObject -Class Win32_BIOS 2.获取内存信息: Get-WMIObject -Class Win32_PhysicalMemory 3.查看CPU信息: Get-WMIObject -Class Win32_Processor 4.查看硬盘信息: Get-WMIObject -Class Win32_DiskDrive

使用python获取CPU和内存信息的思路与实现(linux系统)

linux里一切皆为文件,在linux/unix的根目录下,有个/proc目录,这个/proc 是一种内核和内核模块用来向进程(process)发送信息的机制(所以叫做"/proc"),这个伪文件系统允许与内核内部数据结构交互,获取有关进程的有用信息,在运行中(on the fly)改变设置(通过改变内核参数).与其他文件系统不同,/proc 存在于内存而不是硬盘中.proc 文件系统提供的信息如下: ?进程信息:系统中的任何一个进程,在 proc 的子目录中都有一个同名的进程 ID,

Qt 获取CPU信息

在Qt中调用Windows API GetSystemInfo可以获取CPU的相关信息,使用Qt的界面控件显示在界面上.在实现的过程中遇到了一个问题,就是显示地址信息在界面控件上. 试了好几种方法,都不能显示,最后想到了格式化函数sprintf,将地址转为char类型的数组或者指针,再转为字符串就可以正常显示了. 如果有人有更好的方法来显示地址,欢迎交流. 完整代码: #pragma execution_character_set("utf-8") #ifndef QCPUINFO_H

用C#获取电脑硬件信息

现在我将来解释如何在C#中用WMI(Windows Management Instrumentation)来获取电脑的硬件信息. 我们的目的是用WMI的api在C#下获取电脑的以下信息: 物理处理器的数量 逻辑处理器的数量 位数 系统构架 内核数量 在Visual Studio中创建一个控制台应用程序,并且右击引用然后选择"添加引用",再选择"System.Management". 现在已经通过using语句包括了System.Management,你可以在你的代码

[转帖]如何在Linux上使用命令行查看硬件信息

如何在Linux上使用命令行查看硬件信息 时间:2016-01-13   作者:admin 分类:新手入门 阅读:126次 http://embeddedlinux.org.cn/emb-linux/entry-level/201601/13-4889.html lscpu 原来更简单.. 在 Linux 中,可用于检查和查看硬件信息的命令有很多.其中某些命令可以输出特定硬件和信息,例如:CPU 和内存等.本教程列出一些 Linux 上查看硬件信息的常用命令,以帮助大家快速输出硬件的配置细节.

Android中获取CPU负载和进程cpu时间

android系统中有一个ProcessStats类,我们可以使用它来获取系统的负载情况及进程时间. 实现原理是读取/proc目录下的.linux系统运行时,内核会去更新 /proc目录下的文件,将PID的运行情况写入相应的文件中.我们主要关注以下文件 1. /proc/stat 该文件包含了从系统启动开始累积到当前时刻的CPU活动信息. 看下我手机的情况,如下 cat /proc/stat cpu  14869 5121 19794 156065 3114 0 26 0 0 0 cpu0 10

Python运维-获取当前操作系统的各种信息

#通过Python的psutil模块,获取当前系统的各种信息(比如内存,cpu,磁盘,登录用户等),并将信息进行备份 # coding=utf-8 # 获取系统基本信息 import sys import psutil import time import os #获取当前时间 time_str = time.strftime( "%Y-%m-%d", time.localtime( ) ) file_name = "./" + time_str + ".