官网找到一个例子,根据例子修改下可以获取很多信息

#define _WIN32_DCOM
#include <iostream>
using namespace std;
#include <comdef.h>
#include <Wbemidl.h> #pragma comment(lib, "wbemuuid.lib") int main(int argc, char **argv)
{
HRESULT hres; // Step 1: --------------------------------------------------
// Initialize COM. ------------------------------------------ hres = CoInitializeEx(, COINIT_MULTITHREADED);
if (FAILED(hres))
{
cout << "Failed to initialize COM library. Error code = 0x"
<< hex << hres << endl;
return ; // Program has failed.
} // Step 2: --------------------------------------------------
// Set general COM security levels -------------------------- hres = CoInitializeSecurity(
NULL,
-, // COM authentication
NULL, // Authentication services
NULL, // Reserved
RPC_C_AUTHN_LEVEL_DEFAULT, // Default authentication
RPC_C_IMP_LEVEL_IMPERSONATE, // Default Impersonation
NULL, // Authentication info
EOAC_NONE, // Additional capabilities
NULL // Reserved
); if (FAILED(hres))
{
cout << "Failed to initialize security. Error code = 0x"
<< hex << hres << endl;
CoUninitialize();
return ; // Program has failed.
} // Step 3: ---------------------------------------------------
// Obtain the initial locator to WMI ------------------------- IWbemLocator *pLoc = NULL; hres = CoCreateInstance(
CLSID_WbemLocator,
,
CLSCTX_INPROC_SERVER,
IID_IWbemLocator, (LPVOID *) &pLoc); if (FAILED(hres))
{
cout << "Failed to create IWbemLocator object."
<< " Err code = 0x"
<< hex << hres << endl;
CoUninitialize();
return ; // Program has failed.
} // Step 4: -----------------------------------------------------
// Connect to WMI through the IWbemLocator::ConnectServer method IWbemServices *pSvc = NULL; // Connect to the root\cimv2 namespace with
// the current user and obtain pointer pSvc
// to make IWbemServices calls.
hres = pLoc->ConnectServer(
_bstr_t(L"ROOT\\CIMV2"), // Object path of WMI namespace
NULL, // User name. NULL = current user
NULL, // User password. NULL = current
, // Locale. NULL indicates current
NULL, // Security flags.
, // Authority (for example, Kerberos)
, // Context object
&pSvc // pointer to IWbemServices proxy
); if (FAILED(hres))
{
cout << "Could not connect. Error code = 0x"
<< hex << hres << endl;
pLoc->Release();
CoUninitialize();
return ; // Program has failed.
} cout << "Connected to ROOT\\CIMV2 WMI namespace" << endl; // Step 5: --------------------------------------------------
// Set security levels on the proxy ------------------------- hres = CoSetProxyBlanket(
pSvc, // Indicates the proxy to set
RPC_C_AUTHN_WINNT, // RPC_C_AUTHN_xxx
RPC_C_AUTHZ_NONE, // RPC_C_AUTHZ_xxx
NULL, // Server principal name
RPC_C_AUTHN_LEVEL_CALL, // RPC_C_AUTHN_LEVEL_xxx
RPC_C_IMP_LEVEL_IMPERSONATE, // RPC_C_IMP_LEVEL_xxx
NULL, // client identity
EOAC_NONE // proxy capabilities
); if (FAILED(hres))
{
cout << "Could not set proxy blanket. Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return ; // Program has failed.
} // Step 6: --------------------------------------------------
// Use the IWbemServices pointer to make requests of WMI ---- // For example, get the name of the operating system
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("SELECT * FROM Win32_OperatingSystem"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator); if (FAILED(hres))
{
cout << "Query for operating system name failed."
<< " Error code = 0x"
<< hex << hres << endl;
pSvc->Release();
pLoc->Release();
CoUninitialize();
return ; // Program has failed.
} // Step 7: -------------------------------------------------
// Get the data from the query in step 6 ------------------- IWbemClassObject *pclsObj = NULL;
ULONG uReturn = ; while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, ,
&pclsObj, &uReturn); if( == uReturn)
{
break;
} VARIANT vtProp; // Get the value of the Name property
hr = pclsObj->Get(L"Name", , &vtProp, , );
wcout << " OS Name : " << vtProp.bstrVal << endl;
VariantClear(&vtProp); pclsObj->Release();
} // Cleanup
// ======== pSvc->Release();
pLoc->Release();
pEnumerator->Release();
CoUninitialize(); return ; // Program successfully completed. }

下面列出了常用信息的WMI类:

Win32_Processor                        //CPU 处理器
Win32_PhysicalMemory                   // 物理内存
Win32_Keyboard                         // 键盘
Win32_PointingDevice                   // 点输入设备,如鼠标
Win32_DiskDrive                        // 硬盘驱动器
Win32_CDROMDrive                       // 光盘驱动器
Win32_BaseBoard                        // 主板
Win32_BIOS                             //BIOS 芯片
Win32_ParallelPort                     // 并口
Win32_SerialPort                       // 串口
Win32_SoundDevice                      // 多媒体设置
Win32_USBController                    //USB 控制器
Win32_NetworkAdapter                   // 网络适配器
Win32_NetworkAdapterConfiguration      // 网络适配器设置
Win32_Printer                          // 打印机
Win32_PrinterConfiguration             // 打印机设置
Win32_PrintJob                         // 打印机任务
Win32_TCPIPPrinterPort                 // 打印机端口
Win32_POTSModem                        //MODEM
Win32_POTSModemToSerialPort            //MODEM 端口
Win32_DesktopMonitor                   // 显示器
Win32_VideoController                  // 显卡细节。
Win32_VideoSettings                    // 显卡支持的显示模式。
Win32_TimeZone                         // 时区
Win32_SystemDriver                     // 驱动程序
Win32_DiskPartition                    // 磁盘分区
Win32_LogicalDisk                      // 逻辑磁盘
Win32_LogicalMemoryConfiguration       // 逻辑内存配置
Win32_PageFile                         // 系统页文件信息
Win32_PageFileSetting                  // 页文件设置
Win32_BootConfiguration                // 系统启动配置
Win32_OperatingSystem                  // 操作系统信息
Win32_StartupCommand                   // 系统自动启动程序
Win32_Service                          // 系统安装的服务
Win32_Group                            // 系统管理组
Win32_GroupUser                        // 系统组帐号
Win32_UserAccount                      // 用户帐号
Win32_Process                          // 系统进程
Win32_Thread                           // 系统线程
Win32_Share                            // 共享
Win32_NetworkClient                    // 已安装的网络客户端
Win32_NetworkProtocol                  // 已安装的网络协议

MSDN官网关于WMI的demo程序

MSDN官网关于WMI定义的所有类信息

PS:过两天我会把我修改的程序传上来,实现了 CPU编号、序列号、型号; 硬盘序列号;网卡MAC地址、IP地址、当前状态,这些信息的获取。

C++ WMI获取系统硬件信息(CPU/DISK/NetWork etc)的更多相关文章

  1. android 获取系统硬件信息

    一,首先设置权限访问: <uses-permission android:name="android.permission.READ_PHONE_STATE" />  ...

  2. 通过wmi获取本地硬件信息的一些疑问。

    通过wmi获取本地硬件信息的一些疑问. http://bbs.csdn.net/topics/391017789 http://blog.csdn.net/xcntime/article/detail ...

  3. 获取系统相关信息 (CPU使用率 内存使用率 系统磁盘大小)

    引言 在软件开个过程中,对于软件的稳定性和使用率也是我们需要关注的 .  使用sigar来监控,简单方便!  使用说明:下载sigar jar及配合sigar的dll文件来用,需要将dll文件放到JD ...

  4. c# WMI获取机器硬件信息(硬盘,cpu,内存等)

    using System; using System.Collections.Generic; using System.Globalization; using System.Management; ...

  5. C/C++通过WMI和系统API函数获取获取系统硬件配置信息

    转载:http://www.cnblogs.com/renyuan/archive/2012/12/29/2838716.html 转载:http://blog.csdn.net/jhqin/arti ...

  6. C#获取电脑硬件信息(CPU ID、主板ID、硬盘ID、BIOS编号)

    最近学习过程中,想到提取系统硬件信息做一些验证,故而对网上提到的利用.NET System.Management类获取硬件信息做了进一步的学习.验证.验证是分别在4台电脑,XP SP3系统中进行,特将 ...

  7. (转)IBM AIX系统硬件信息查看命令(shell脚本)

    IBM AIX系统硬件信息查看命令(shell脚本) 原文:http://blog.itpub.net/22085031/viewspace-1054015/ 查看IBM AIX系统的主机型号.序列号 ...

  8. Linux查看系统硬件信息命令

    Linux查看系统硬件信息命令 查看磁盘类型(是否SSD) cat /sys/block/sda/queue/rotational code:0 SSD盘 code:1 SATA盘 查看物理CPU个数 ...

  9. 利用CMD查看系统硬件信息

    利用CMD查看系统硬件信息对于在windows下查看系统信息大家一定不陌生了,我现在说几个最常用的方法,对命令感兴趣的朋友看看,(给菜鸟看的,老手就不要笑话我了,大家都是从那个时候过来的,^_^).一 ...

随机推荐

  1. 如何机智判断页面是刷新还是关闭,背景:vue项目,需求:关闭页面,下次直接跳到登陆页

    最近项目有这么个需求:要在关闭当前系统的窗口的时候,退出登录, 因为如果不退出登录可能存在安全风险,其实我想说,电脑没事别借给别人活着离开工位记得一定要锁屏,其实我们设置了cookie失效时间的,过了 ...

  2. 【重学计算机】机组D5章:指令系统

    1. 指令系统基本概念 指令集:一台机器所有指令的集合.系列机(同一公司不同时期生产):兼容机(不同公司生产) 指令字长:指令中包含的二进制位数,有等长指令.变长指令. 指令分类 根据层次结构:高级. ...

  3. 补习系列(14)-springboot redis 整合-数据读写

    目录 一.简介 二.SpringBoot Redis 读写 A. 引入 spring-data-redis B. 序列化 C. 读写样例 三.方法级缓存 四.连接池 小结 一.简介 在 补习系列(A3 ...

  4. 权限管理系统之SpringBoot集成LayUI实现后台管理首页

    万事开头难,昨天一直在构思用户权限管理系统怎么实现,实现哪些需求,采用什么技术等,也在网上百度了好多,计划使用SpringBoot + Mybatis + thymeleaf  + LayUI + S ...

  5. 解读经典《C#高级编程》继承 页107-113.章4

    前言 本章节开始讲接口. 接口 接口的声明很像抽象类,有方法的声明但无方法体.但它比抽象类限制更多.和类比起来,接口的定义有众多限制. 接口只能包含声明,而无方法体 接口只能包含方法.属性.索引器.事 ...

  6. pytorch深度学习60分钟闪电战

    https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html 官方推荐的一篇教程 Tensors #Construct a ...

  7. WebApi中使用Ninject 依赖注入

    之前Ninject依赖注入是在MVC中使用,最近在WebApi中使用,用之前的MVC方式发现使用接口注入,一直是Null错误,网上查询了一些资源,总结一下,以后备用. 主要分为以下几步骤: 在NuGe ...

  8. 从零开始学安全(四十六)●sqli-labs 1-4关 涉及的知识点

    Less-1 到Less-4  基础知识注入 我们可以在 http://127.0.0.1/sqllib/Less-1/?id=1 后面直接添加一个 ‘ ,来看一下效果: 从上述错误当中,我们可以看到 ...

  9. ASP.net<a>标签跨页面传参数

    //在goodsDetail.aspx页面接收 <script> //加载事件 $(function () { //第一种方式 var id=GetQueryString("id ...

  10. 在表单提交之前做校验-利用jQuery的submit方法

    点击表单中的提交按钮,默认就会提交表单,如果要在表单提交之前做一些校验,那么就可以用jQuery的submit方法. 也就是jQuery的submit的方法执行顺序,在表单的提交之前.用法如下: $( ...