最近的任务中有个分支任务, 要求将客户本地计算机Windows操作系统中的软硬件信息记录下来, 给研发看, 辅助调试用.

看到WMI能做这事, codeproject上资料还没有csdn上多~

有人反映WMI比较慢, 这对于我的任务倒没啥影响~, 在线程中执行, 界面上给个等待进度提示就可以.

参考:

Computer System Hardware Classes (Windows)

http://msdn.microsoft.com/en-us/library/windows/desktop/aa389273%28v=vs.85%29.aspx

http://www.codeproject.com/Articles/5853/Getting-Information-from-WMI-in-Visual-C

http://www.codeproject.com/Articles/18135/Getting-the-Network-Adaptor-MAC-Address-with-WMI

http://www.codeproject.com/Articles/37707/Process-Create-Notification-using-EnumProcess

http://www.codeproject.com/Articles/10539/Making-WMI-Queries-In-C

整理了一个WMI Data 类, 以后复用. CWmiDataHelper用来连续执行SQL查询WMI中的内容. 还挺好用的~

只需要执行一个方法:

WmiData.ExecComQuery

取数据还是弄得挺丑, 得再想想. 实际取数据的时候, 要取多个数据.  e.g. 取计算机逻辑分区信息 分区No.1(分区盘符, 分区大小, 分区格式, 所在物理硬盘序列号)

以后有时间, 再整理一个取WMI逻辑数据的类, 此类调用CWmiDataHelper来工作.

此数据主要给研发看, 比如我自己, 看到测试程序的结果, 我也能明白.

剩下的就是工作量, 整的好看些. 如果有时间的话, 要精益求精的去提高用户体验, 假设用户就是我一个人, 也是如此.

计算机硬件检测程序, 一定也调用了WMI功能. 只是人家做的非常精细.

测试程序:

// srcWmiData.cpp : Defines the entry point for the console application.
//#include "stdafx.h"
#include "Helper/WmiData/WmiDataHelper.h"int _tmain(int argc, _TCHAR* argv[])
{int                                 iIndex          = 0;INT64                               int64Size       = 0;INT64                               int64SizeCur    = 0;size_t                              nSize           = 0;size_t                              nSizeCur        = 0;std::wstring                        strTmpW;std::vector<std::wstring>           vecResult;std::vector<std::wstring>::iterator it;CWmiDataHelper                      WmiData;/// 安装程序列表 Win32_Productif(WmiData.ExecComQuery(L"select * from  Win32_Product", L"Name", vecResult)){int64Size = 0;_tprintf(L"Win32_Product Name = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++)_tprintf(L"%s\r\n", (*it).c_str());}/// Win32_NetworkAdapterConfiguration Ip地址 IPAddressif(WmiData.ExecComQuery(L"select * from  Win32_NetworkAdapterConfiguration", L"IPAddress", vecResult)){int64Size = 0;_tprintf(L"Win32_NetworkAdapterConfiguration IPXAddress = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++)_tprintf(L"%s\r\n", (*it).c_str());}/// 网卡名称 Win32_NetworkAdapter Nameif(WmiData.ExecComQuery(L"select * from  Win32_NetworkAdapter", L"Name", vecResult)){int64Size = 0;_tprintf(L"Win32_NetworkAdapter Name = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++)_tprintf(L"%s\r\n", (*it).c_str());}/// 网卡Mac地址 Win32_NetworkAdapter MACAddressif(WmiData.ExecComQuery(L"select * from  Win32_NetworkAdapter", L"MACAddress", vecResult)){int64Size = 0;_tprintf(L"Win32_NetworkAdapter MACAddress = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++)_tprintf(L"%s\r\n", (*it).c_str());}/// 磁盘分区 Win32_DiskPartitionif(WmiData.ExecComQuery(L"select * from  Win32_DiskPartition", L"DeviceID", vecResult)){int64Size = 0;_tprintf(L"Win32_DiskDrive Capacity = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++)_tprintf(L"%s\r\n", (*it).c_str());}// 分区类型if(WmiData.ExecComQuery(L"select * from  Win32_DiskPartition", L"Type", vecResult)){int64Size = 0;_tprintf(L"Win32_DiskDrive Capacity = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++)_tprintf(L"%s\r\n", (*it).c_str());}if(WmiData.ExecComQuery(L"select * from  Win32_DiskPartition", L"Size", vecResult)){int64Size = 0;_tprintf(L"Win32_DiskDrive Capacity = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){strTmpW = (*it).c_str();int64SizeCur = _ttoi64(strTmpW.c_str());int64Size = int64SizeCur / 1024 / 1024 / 1024;_tprintf(L"%dGB\r\n", int64Size);}}/// 硬盘 Win32_DiskDriveif(WmiData.ExecComQuery(L"select * from  Win32_DiskDrive", L"Capabilities", vecResult)){int64Size = 0;_tprintf(L"Win32_DiskDrive Capacity = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){strTmpW = (*it).c_str();int64SizeCur = _ttoi64(strTmpW.c_str());int64Size += int64SizeCur;}_tprintf(L"%dGB\r\n", int64Size);}/// 内存 Win32_PhysicalMemory, 数据是int64!if(WmiData.ExecComQuery(L"select * from  Win32_PhysicalMemory", L"Capacity", vecResult)){int64Size = 0;_tprintf(L"Win32_PhysicalMemory Capacity = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){strTmpW = (*it).c_str();int64SizeCur = _ttoi64(strTmpW.c_str());int64Size += int64SizeCur;}_tprintf(L"%dMB\r\n", int64Size / 1024 / 1024);}/// 可用内存 Win32_PerfFormattedData_PerfOS_Memoryif(WmiData.ExecComQuery(L"select * from Win32_PerfFormattedData_PerfOS_Memory", L"AvailableMBytes", vecResult)){nSize = 0;_tprintf(L"Win32_PerfFormattedData_PerfOS_Memory Capacity = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){nSizeCur = _ttol((*it).c_str());nSize += nSizeCur;}_tprintf(L"%dMB\r\n", nSize);}/// 得处理器信息/// CPU 厂家 Manufacturerif(WmiData.ExecComQuery(L"select * from win32_Processor", L"Manufacturer", vecResult)){_tprintf(L"cpu Manufacturer = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){_tprintf(L"%s\r\n", (*it).c_str());}}/// CPU Nameif(WmiData.ExecComQuery(L"select * from win32_Processor", L"Name", vecResult)){_tprintf(L"Name = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){_tprintf(L"%s\r\n", (*it).c_str());}}/// CPU占用率if(WmiData.ExecComQuery(L"select * from win32_Processor", L"LoadPercentage", vecResult)){_tprintf(L"cpu LoadPercentage = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){_tprintf(L"%s\r\n", (*it).c_str());}}/// 得主板信息/// 生产厂家 Manufacturerif(WmiData.ExecComQuery(L"select * from Win32_BaseBoard", L"Manufacturer", vecResult)){_tprintf(L"MainBoard = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){_tprintf(L"%s\r\n", (*it).c_str());}}/// 主板型号if(WmiData.ExecComQuery(L"select * from Win32_BaseBoard", L"Product", vecResult)){_tprintf(L"MainBoard = :\r\n");for(it = vecResult.begin(); it != vecResult.end(); it++){_tprintf(L"%s\r\n", (*it).c_str());}}getchar();return 0;
}/** run result
Windows Mobile 5.0 SDK R2 for Pocket PC
Catalyst Control Center - Branding
wpdtools_x64fre
Microsoft Visual Studio 2010 IntelliTrace Collection (x64)
Intel?Trusted Connect Service Client
smartcardsamples
Device Simulation Framework 1.0.1
eventsample
bussamples
CCC Help Hungarian
Microsoft Visual Studio 2005 64bit Prerequisites (x64) - ENU
Visual Studio .NET Enterprise Architect 2003 - CHS
biometrictools_x86fre
swtuner
oacr_x86fre
CCC Help Thai
wpdsamples
avstreamsamples
HydraVision
Microsoft Visual Studio 2008 Professional Edition - ENU
Catalyst Control Center InstallProxy
Windows Management Instrumentation (WMI) SDK (3790.0)
usbsamples
Visual Studio.NET Baseline - CHS
pfd_ia64fre
sensorsamples
buildtools_x86fre
Microsoft Document Explorer 2005
wdtfbinaries_ia64fre
setuptools_x86fre
CCC Help Chinese Standard
wnetlibs_x86fre
setupsamples
drvtools_x86fre
CCC Help Finnish
Microsoft Team Foundation Server 2010 Object Model - ENU
ccc-utility64
Debugging Tools for Windows (3790.0)
bluetoothsamples
O&O Defrag Professional
Microsoft .NET Framework 2.0 SDK (x64) - ENU
avstreamtools_ia64fre
Snagit 10.0.1
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729
avstreamtools_x64fre
wpdtools_x86fre
AnkhSVN 2.3.10838.1211
Microsoft FrontPage Client - CHS
tools_ia64fre
Adobe Reader 9.5.3 - Chinese Simplified
fireflysample
MSDN Library for Visual Studio 2005
Microsoft Visual Studio 2008 Remote Debugger - ENU
vistalibs_ia64fre
CCC Help Spanish
libs_x64fre
portiosample
Microsoft Visual C++ 2008 Redistributable - x86 9.0.21022
CCC Help Greek
modemtools
toastermetadatapackagesample
Tablet PC SDK (3790.0)
networksamples
wdtfbinaries_x86fre
CCC Help German
wsdtool_ia64fre
SlickEdit 2012 x64 (17.0.1)
Visual Studio .NET Prerequisites - English
Microsoft Visual Studio 2010 Office Developer Tools (x64)
dfx_x64fre
tools-winPre2k
drvtools_ia64fre
tools-netware
drvtools_x64fre
pcidrvsample
Microsoft Visual Studio 2005 SDK February 2007
MSDN Library for Visual Studio .NET 2003 - ????
wpdtools_ia64fre
Microsoft Visual Studio 2008 Performance Collection Tools - ENU
printtools_x64fre
infsample_x64fre
CCC Help Chinese Traditional
generaltools_x86fre
installhelp
Microsoft Visual C++ 2005 Redistributable (x64)
Microsoft Windows Driver Kit Documentation 7600.091201
wnetlibs_x64fre
ifssamples
Microsoft Data Access Components (MDAC) SDK (Ver 2.7) (3790.0)
Renesas Electronics USB 3.0 Host Controller Driver
offreg_ia64fre
CCC Help Swedish
Microsoft Visual C++ 2005 Redistributable (x64)
imagingtools_ia64fre
wsdtool_x64fre
CCC Help Danish
AMD Media Foundation Decoders
ATI AVIVO64 Codecs
generaltools_x64fre
setuptools_x64fre
cancelsample
headers
DSF-KitSetup
wxplibs_x86fre
printtools_ia64fre
networklibraries_ia64fre
hidsampleinput
debugfiles_win7
setuptools_ia64fre
tools-linux
AMD Catalyst Install Manager
tracingtool_x86fre
libs_ia64fre
VMware Workstation
Microsoft Help Viewer 1.0
VC Runtimes MSI
toolindex
bluetoothtools_x64fre
pnptools_x64fre
sideshowsamples
Microsoft Windows SDK for Visual Studio 2008 SP1 Win32 Tools
hidsamples
buildtools_ia64fre
hid_inputsamples
Microsoft Visual Studio 2010 Ultimate - ENU
imagingtools_x86fre
Microsoft Visual C++ 2005 Redistributable
sdv
wdftools_x86fre
Catalyst Control Center Graphics Previews Common
evntdrvsample
biometrictools_x64fre
chkinftool_x86fre
CCC Help Norwegian
tracingtool_x64fre
umdfsamples
generaltools_ia64fre
bluetoothtools_ia64fre
CCC Help Turkish
CCC Help Russian
pfd_x86fre
tools-solaris
Windows Media Services SDK (3790.0)
imagingtools_x64fre
Catalyst Control Center Localization All
Microsoft Document Explorer 2008
Microsoft Visual C++ 2010  x64 Redistributable - 10.0.30319
Microsoft Visual C++ 2005 Redistributable
tools-windows
networklibraries_x64fre
pnpportssample
printtools_x86fre
pnptools_ia64fre
Microsoft Windows SDK for Visual Studio 2008 SDK Reference Assemblies and Intell
iSense
dsfsamples
Windows Mobile 5.0 SDK R2 for Smartphone
wmisamples
Internet Information Server (IIS) SDK (Version 5.1) (3790.0)
vistalibs_x64fre
wcoinstallers
readme
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.4148
Microsoft Visual C++ 2010  x86 Redistributable - 10.0.30319
Internet Development SDK (Version 6.0) (3790.0)
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17
displaysamples
AMD APP SDK Runtime
Visual C++ 2008 x86 Runtime - (v9.0.30729)
pfd_x64fre
ASUS VGA Driver
dfx_x86fre
storagesamples
tools-freebsd
Microsoft Visual Studio 2010 Performance Collection Tools - ENU
Microsoft Visual Studio Team System 2008 Team Suite - ENU
tools_x86fre
Microsoft .NET Framework 1.1
wnetlibs_ia64fre
CCC Help Italian
Windows Installer SDK (Version 2.0) (3790.0)
Microsoft Device Emulator (64 bit) version 3.0 - ENU
offreg_x64fre
powermanagement_ia64fre
Microsoft Visual C++ 2008 ATL Update kb973924 - x86 9.0.30729.4148
vistalibs_x86fre
Microsoft Visual Studio Macro Tools
bluetoothtools_x86fre
Core SDK (Windows Server 2003) (3790.0)
MSDN Library for Visual Studio 2008 SP1 - ENU
Debugging Tools for Windows (x64)
buildsamples
VisualSVN Server 2.5.4
powermanagement_x64fre
ioctlsample
CCC Help English
Catalyst Control Center InstallProxy
TortoiseSVN 1.7.6.22632 (64 bit)
wdtfbinaries_x64fre
tools_x64fre
Utility
RAMDisk
WSC Real 09
CCC Help Czech
tracingtool_ia64fre
irsamples
audiosamples
CCC Help Korean
wsdtool_x86fre
Microsoft Windows SDK for Visual Studio 2008 Headers and Libraries
infsample_x86fre
offreg_x86fre
wdftools_x64fre
???? 0.46
Win32_NetworkAdapterConfiguration IPXAddress = :192.168.70.60192.168.132.1
192.168.70.1Win32_NetworkAdapter Name = :
WAN Miniport (SSTP)
WAN Miniport (IKEv2)
WAN Miniport (L2TP)
WAN Miniport (PPTP)
WAN Miniport (PPPOE)
WAN Miniport (IPv6)
WAN Miniport (Network Monitor)
Realtek PCIe GBE Family Controller
WAN Miniport (IP)
Microsoft ISATAP Adapter
RAS Async Adapter
Microsoft ISATAP Adapter #2
Microsoft 6to4 Adapter
Microsoft Teredo Tunneling Adapter
VMware Virtual Ethernet Adapter for VMnet1
VMware Virtual Ethernet Adapter for VMnet8
Microsoft ISATAP Adapter #3
Microsoft ISATAP Adapter #4
Win32_NetworkAdapter MACAddress = :8C:89:A5:67:BC:C600:50:56:C0:00:01
00:50:56:C0:00:08Win32_DiskDrive Capacity = :
Disk #1, Partition #0
Disk #0, Partition #0
Disk #2, Partition #0
Win32_DiskDrive Capacity = :
Installable File System
Installable File System
Unknown
Win32_DiskDrive Capacity = :
111GB
1863GB
3GB
Win32_DiskDrive Capacity = :
630GB
Win32_PhysicalMemory Capacity = :
16384MB
Win32_PerfFormattedData_PerfOS_Memory Capacity = :
9738MB
cpu Manufacturer = :
GenuineIntel
Name = :
Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz
cpu LoadPercentage = :
0
MainBoard = :
MSI
MainBoard = :
Z68A-G43 (G3) (MS-7750)*/

WMI数据查询类封装如下:

/// @file           WmiDataConst.h
/// @brief          ...#ifndef __WMI_DATA_CONST_H__
#define __WMI_DATA_CONST_H__#endif
/// @file           WmiDataHelper.h
/// @brief          通过WMI取操作系统数据#ifndef __WMI_DATA_HELPER_H__
#define __WMI_DATA_HELPER_H__#include <vector>
#include <wbemcli.h>
#include "WmiDataConst.h"class CWmiDataHelper
{
public:CWmiDataHelper();virtual ~CWmiDataHelper();/// @fn        ExecComQuery/// @brief    按照SQL语句, 进行COM查询, 查询的多条结果, 压入vecResult返回/// @param  IN const wchar_t * pcSqlW, 负荷COM查询规范的SQL语句/// @param  OUT vector<std::wstring> vecResult, 返回的结果集/// @return  boolen, true = 查询成功, false = 查询失败bool ExecComQuery(IN const wchar_t * pcSqlW, IN const wchar_t * pcPropertyValue, OUT std::vector<std::wstring> & vecResult);private:/// 设置,取得 标记_COM是否有效void SetComValid(bool bValid) {m_bIsComValid = bValid;}bool GetComValid() {return m_bIsComValid;}bool SetComSecurity();bool CreateComInstance();bool ConnectComServer();bool ProcessWbemClassObject(IN ULONG ulRc, IN IWbemClassObject ** ppClassObject, IN const wchar_t * pcPropertyValue,OUT std::vector<std::wstring> & vecResult);void VariantToString(const LPVARIANT pVar, std::wstring & strRc);void DataInit();void DataUnInit();private:bool             m_bIsComValid;     ///< COM环境是否有效IWbemLocator *   m_pIWbemLocator;IWbemServices *  m_pWbemServices;
};#endif
/// @file           WmiDataHelper.cpp
/// @brief         ...#include "stdafx.h"
#include "wbemidl.h"
#include <comdef.h>
#include <string>
#include <strsafe.h>#include "WmiDataHelper.h"
#pragma comment(lib, "wbemuuid.lib")CWmiDataHelper::CWmiDataHelper()
{DataInit();SetComValid(S_OK == CoInitialize(NULL));SetComValid(SetComSecurity());SetComValid(CreateComInstance());SetComValid(ConnectComServer());
}CWmiDataHelper::~CWmiDataHelper()
{DataUnInit();CoUninitialize();
}bool CWmiDataHelper::SetComSecurity()
{HRESULT    hRc =  S_OK;if(!GetComValid())return false;/// Security needs to be initialized in XP first and this was the major problem /// why it was not working in XP.hRc = CoInitializeSecurity( NULL,-1,NULL,NULL,RPC_C_AUTHN_LEVEL_PKT,RPC_C_IMP_LEVEL_IMPERSONATE,NULL,EOAC_NONE,0);return ((S_OK != hRc ) && (RPC_E_TOO_LATE != hRc)) ? false : true;
}bool CWmiDataHelper::CreateComInstance()
{HRESULT  hRc   = S_OK;if(!GetComValid())return false;hRc = CoCreateInstance( CLSID_WbemAdministrativeLocator,NULL ,CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER , IID_IUnknown ,(void **) &m_pIWbemLocator);return (S_OK == hRc);
}bool CWmiDataHelper::ConnectComServer()
{HRESULT  hRc                   = S_OK;BSTR        bstrNamespace = (L"root\\cimv2");if(!GetComValid())return false;hRc = m_pIWbemLocator->ConnectServer(   bstrNamespace,  // NamespaceNULL,           // UseridNULL,           // PWNULL,           // Locale0,              // flagsNULL,           // AuthorityNULL,           // Context&m_pWbemServices);return (S_OK == hRc);
}bool CWmiDataHelper::ExecComQuery(  IN const wchar_t * pcSqlW, IN const wchar_t * pcPropertyValue, OUT std::vector<std::wstring> & vecResult)
{bool                    bRc         =  true;HRESULT                 hRc         =  S_OK;BSTR                    strQuery    =  _bstr_t(pcSqlW);BSTR                    strQL       =  (L"WQL");IEnumWbemClassObject *  pEnumObject =  NULL;const size_t            nClassObject    =   1;const ULONG             ulCount         =   1;  ///< pClassObject 的数量是1IWbemClassObject *      pClassObject[nClassObject];ULONG                   ulRc    = 0;ULONG                   ulIndex = 0;vecResult.clear();for (ulIndex = 0; ulIndex < nClassObject; ulIndex++)pClassObject[ulIndex] = NULL;if(!GetComValid())return false;hRc = m_pWbemServices->ExecQuery(strQL, strQuery,WBEM_FLAG_RETURN_IMMEDIATELY,NULL,&pEnumObject);if (S_OK != hRc)return false;hRc = pEnumObject->Reset();if (S_OK != hRc){bRc = false;goto ExecComQuery_END;}do{hRc = pEnumObject->Next(WBEM_INFINITE, ulCount, &pClassObject[0], &ulRc);if (S_OK != hRc)goto ExecComQuery_END;ProcessWbemClassObject(ulRc, &pClassObject[0], pcPropertyValue, vecResult);for (ulIndex = 0; ulIndex < nClassObject; ulIndex++){if(NULL != pClassObject[ulIndex]){pClassObject[ulIndex]->Release();pClassObject[ulIndex] = NULL;}}} while (WBEM_S_NO_ERROR == hRc);ExecComQuery_END:for (ulIndex = 0; ulIndex < nClassObject; ulIndex++){if (NULL != pClassObject[ulIndex]){pClassObject[ulIndex]->Release();pClassObject[ulIndex] = NULL;}}if (NULL != pEnumObject)pEnumObject->Release();return bRc;
}void CWmiDataHelper::VariantToString(const LPVARIANT pVar, std::wstring & strRc)
{  USES_CONVERSION;  CComBSTR HUGEP *    pBstr   = NULL;BYTE HUGEP *        pBuf    = NULL;LONG                llow    = 0;LONG                lhigh   = 0;LONG                lIndex  = 0;HRESULT             hRc     = S_OK;  wchar_t             cBufW[_MAX_PATH];switch(pVar->vt)  {  case VT_BSTR:  {  strRc=(wchar_t *)_bstr_t(pVar->bstrVal);  }  break;  case VT_BOOL:  {  if(VARIANT_TRUE==pVar->boolVal)   strRc = L"TRUE";  else  strRc=  L"FALSE";  }  break;  case VT_I4:  {  StringCchPrintf( cBufW, sizeof(cBufW) / sizeof(wchar_t), TEXT("%d"), pVar->lVal);strRc = cBufW;}  break;  case VT_UI1:  {  StringCchPrintf( cBufW, sizeof(cBufW) / sizeof(wchar_t), TEXT("%d"), pVar->bVal);strRc = cBufW;}  break;  case VT_UI4:  {  StringCchPrintf( cBufW, sizeof(cBufW) / sizeof(wchar_t), TEXT("%d"), pVar->ulVal);strRc = cBufW;}  break;  case (VT_BSTR | VT_ARRAY):  {  hRc=SafeArrayAccessData(pVar->parray,(void HUGEP**)&pBstr);  hRc=SafeArrayUnaccessData(pVar->parray);  strRc = (wchar_t *)_bstr_t(pBstr->m_str);  }  break;  case (VT_I4 | VT_ARRAY):  {  SafeArrayGetLBound(pVar->parray, 1, &llow);   SafeArrayGetUBound(pVar->parray, 1, &lhigh);  hRc = SafeArrayAccessData(pVar->parray,(void HUGEP**)&pBuf);  hRc = SafeArrayUnaccessData(pVar->parray);  strRc = L"";for(lIndex=llow; lIndex<=lhigh; ++lIndex)  {  StringCchPrintf( cBufW, sizeof(cBufW) / sizeof(wchar_t), TEXT("%d"), pBuf[lIndex]);strRc += cBufW;}  }  break;  default:  break;  }
}bool CWmiDataHelper::ProcessWbemClassObject(IN ULONG ulRc, IN IWbemClassObject ** ppClassObject, IN const wchar_t * pcPropertyValue,OUT std::vector<std::wstring> & vecResult)
{VARIANT         v;HRESULT         hRc     = S_OK;ULONG           ulIndex =  0;std::wstring    strW    = L"";wchar_t         cBufW[_MAX_PATH];if ((NULL == ppClassObject) || (NULL == *ppClassObject))return false;VariantInit(&v);for (ulIndex = 0; ulIndex < ulRc; ulIndex++){hRc = (*(ppClassObject + ulIndex))->Get(pcPropertyValue, 0, &v, 0, 0);if(S_OK == hRc){VariantToString(&v, strW);vecResult.push_back(strW);}}VariantClear(&v);return true;
}void CWmiDataHelper::DataInit()
{m_bIsComValid = false;m_pIWbemLocator = NULL;m_pWbemServices = NULL;
}void CWmiDataHelper::DataUnInit()
{if (NULL != m_pWbemServices)m_pWbemServices->Release();if (NULL != m_pIWbemLocator)m_pIWbemLocator->Release();
}

experiment : 使用WMI取本地计算机信息相关推荐

  1. Wireshark使用(捕获过滤器、显示过滤器、TCP交互抓包示例、抓取本地回环数据包等)

    1.捕获过滤器规则 1.1 作用   捕获过滤器在开始捕捉之前设置,用于从源头控制被过滤的包内容,仅符合规则的包会被捕获并记录进捕获日志文件. 1.2 语法规则 字段:[Protocol][Direc ...

  2. 用 Java 实现爬虫 (爬取本地html中的人物信息并可视化人物关系)

    目录 爬虫简介 常用的工具框架 selenium + Jsoup Jsoup介绍 Jsoup的主要功能如下: HTML 相关知识 通过Jsoup元素获取 案例 爬取本地html中的角色信息 HtmlP ...

  3. git gerrit 拉取本地服务器代码出错Unable to negotiate with XX.XX.XX.XX port XX: no matching key exchange me

    ssh 方式 git gerrit 拉取本地服务器代码出错ssh拉取项目 Unable to negotiate with XX.XX.XX.XX port XX:: no matching key ...

  4. 易语言利用WMI取磁盘CPU内存显卡信息源码

    WMI 是 Windows Management Instrumentation (Windows管理工具)的缩写,是内置在操作系统中核心的管理支持技术,通过它可以访问.配置.管理和监视几乎所有的 W ...

  5. 使用WMI对象收集计算机信息

    WMI(windows管理规范),是Windows 2K/XP管理系统的核心:对于其他的Win32操作系统,WMI是一个有用的插件.WMI以CIMOM为基础. CIMOM即公共信息模型对象管理器(Co ...

  6. WMI CIM studio无法连接解决 在XP下wmi取不到值可巧用wmic取值

    原因如下图,通过函数取wmi,很多接口最低要求vista:(xp不支持) 东方不亮西方亮,同事偶然说起他碰到过wmic,让试试,果然可以. 然后就得用到一个工具,WMI CIM studio,网上搜索 ...

  7. 取本地数据_深入理解Kafka服务端之Follower副本如何同步Leader副本的数据

    一.场景分析Kafka采用的是主写主读的方式,即客户端的读写请求都由分区的Leader副本处理,那么Follower副本要想保证和Leader副本数据一致,就需要不断地从Leader副本拉取消息来进行 ...

  8. IDEA MAVEN工程拉取本地jar包

    初接触IDEA的新手,踩坑专家... 今天编译组内的自动化代码,然后发现有几个本地的包,怎么都加不到工程里面,错误信息包括如下: Dependency 'com.oracle:ojdbc6:11.2. ...

  9. python爬取本地天气信息_用Python写一个爬取中国天气网的终端版天气预报爬虫

    导语 前几篇文章介绍了爬取静态网站的主要方法.今天写一个小项目实践一下.本项目可以在终端窗口查询全国3400多个区县的当日天气信息和近七天天气信息. 实现效果 [Python爬虫]写一个爬取中国天气网 ...

最新文章

  1. 用 Python 实现隐身,我可以 | 文末福利
  2. php t double arrow,关于php:php – 语法错误,意外T_DOUBLE_ARROW
  3. 三方库报错真的就没有办法了吗?
  4. 不带头结点链表,尾部插入法创建
  5. react学习(44)----只更新它需要更新的部分
  6. python os模块方法_python os模块方法总结
  7. Intel Core Enhanced Core架构/微架构/流水线 (14) - 存储器/内存读写 Memory Load/Store
  8. java tomcat 读取配置文件端口_跟我学Java编程—应用读写项目配置文件的Properties类...
  9. AI研发新药真有那么神?可能哈佛、斯坦福和阿斯利康实验室都在吹牛
  10. MySQL 事务的实现原理,写得太好了!
  11. sqlite to mysql_SqliteToMysql官方下载
  12. petalinux设计流程
  13. 巴斯勒相机的相机控制类析构函数多次调用的问题
  14. 文件压缩原理是什么?
  15. 恩尼格玛密码机原理解析(Enigma principle )
  16. 举个栗子!Tableau 技巧(183):快速实现部分类别的排序
  17. 关于随机森林randomforest对结果进行分类的原则的个人理解
  18. 2022.8.29-9.4 AI行业周刊(第113期):世界人工智能大会
  19. PyTorch中tensor介绍
  20. Statistics Foundations: 2 统计基础:2 Lynda课程中文字幕

热门文章

  1. 研究生课程教给我什么?
  2. 将源程序变为可执行程序的过程
  3. 新的选择,该如何择业
  4. springboot使用jasper实现报表demo
  5. rocketmq延时消息自定义配置;topic下tag使用
  6. QLineEdit 中使用QML原生虚拟键盘Qt5VirtualKeyboard
  7. 实现网站的中英文转换
  8. 基于Matlab形态学水果蔬菜缺陷检测
  9. 小白向 零基础创建并简单调用钉钉自定义机器人
  10. Abaqus进阶-汽车吸能盒冲击动力学分析 step by step