如何使用c++在windows中获取系统信息 [英] How to get system information in windows with c++

查看:96
本文介绍了如何使用c++在windows中获取系统信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 C++ 代码获取我的系统硬件信息.

I want to get my system hardware information with c++ code.

那么如何用c++在windows中获取系统信息?

So how to get system information in windows with c++ ?

推荐答案

您可以使用 GetSystemInfo 函数获取硬件信息,例如 OEM 标识符、处理器类型、页面大小等.

You can use the GetSystemInfo function to obtain hardware information such as the OEM identifier, processor type, page size, and so on.

#include <windows.h>
#include <stdio.h>
#pragma comment(lib, "user32.lib")

void main()
{
   SYSTEM_INFO siSysInfo;

   // Copy the hardware information to the SYSTEM_INFO structure. 

   GetSystemInfo(&siSysInfo); 

   // Display the contents of the SYSTEM_INFO structure. 

   printf("Hardware information: \n");  
   printf("  OEM ID: %u\n", siSysInfo.dwOemId);
   printf("  Number of processors: %u\n", 
      siSysInfo.dwNumberOfProcessors); 
   printf("  Page size: %u\n", siSysInfo.dwPageSize); 
   printf("  Processor type: %u\n", siSysInfo.dwProcessorType); 
   printf("  Minimum application address: %lx\n", 
      siSysInfo.lpMinimumApplicationAddress); 
   printf("  Maximum application address: %lx\n", 
      siSysInfo.lpMaximumApplicationAddress); 
   printf("  Active processor mask: %u\n", 
      siSysInfo.dwActiveProcessorMask); 
}

参考资料:

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724423(v=vs.85).aspx

https://msdn.microsoft.com/en-us/library/windows/desktop/ms724381(v=vs.85).aspx

http://www.cplusplus.com/forum/windows/124624/

这篇关于如何使用c++在windows中获取系统信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆