WMI - 取本地计算机信息

概述

在看windows下取本地计算机特征码的资料.
以前也取过, 都是用WIN32API来取. 这样取的不全. 有些信息取不到.
现在看的资料是用WMI接口取本地计算机信息, 这样取的全.

还是要有足够的思考和实验时间才能整出好一些的思路和产出, 如果被赶着往前走, 只考虑将眼前的事情凑合干完, 会导致好多细节考虑不到或不是较好的实现思路.

如果是被迫进行一项任务, 即使自己有心将细节做好, 也没有时间去做(思考, 查资料, 做实验).

资料中取硬盘特征码时, 没有判断硬盘是否为可插拔硬盘.
我必须要取固定硬盘的特征码, 做了实验, MediaType的值为 ‘Fixed hard disk media’ 就是固定硬盘.

我还需要取固定网卡的特征码, 资料中没有.
做了实验, 取网卡的类为 Win32_NetworkAdapter.
满足以下条件, 就是固定网卡.

  • 必须有GUID值.
  • PNPDeviceID值中的类别必须属于 PCI, BTH

用WMI能取的计算机信息还很多, 可以参考https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-networkadapter

在这里插入图片描述

这个笔记可以用WMI接口取指定WMI类的计算机信息, 指定上图中4个大类别的不同子类, 结合官方文档中说的类成员名称和类型, 就可以取到MS官方提供的其他计算机信息.

如果自己有时间, 可以做个程序, 将MS提供的WMI类信息全部显示出来, 应该里面有不少好东西.
不过编程方面, 重复的不行, 估计很累.

另外, 官方给的类成员的类型可能不对, 需要自己根据实际接口返回的.vt来修正. 我在取硬盘和网卡信息时, 已经发现有些官方给的类成员类型不对. 如果是通过WMI接口取大量信息时, 最好加入断言, 这样的话, 如果从WMI接口返回的类成员信息的类型不对时, 就可以及时发现止损.

if (VT_BOOL != vt_prop.vt)
		{
			_ASSERT(FALSE);
			break;
		}

官方提供的VT类型列表为 https://learn.microsoft.com/en-us/windows/win32/api/wtypes/ne-wtypes-varenum

网上有一些公版工具可以改硬盘序列号, 网卡序列号. 但是用WMI可以取的硬件信息很多, 可以找一些公版工具无法改的信息作为硬件特征码.
只要是物理上的硬件信息, 这个硬件即使没有被用户使用(e.g. 被停用的物理网卡), 作为硬件特征码也挺靠谱的.

笔记

写了测试程序, 环境vs2019 vc++ console

测试效果

我本地有2个固定硬盘, 3个固定网卡

disk info:
MediaType = Fixed hard disk media
Model = ST2000LM007-1R8174
Size = 2000396321280

disk info:
MediaType = Fixed hard disk media
Model = KBG40ZNS512G NVMe KIOXIA 512GB
Size = 512105932800

network adapter info:
AdapterType : 以太网 802.3
Caption : [00000002] Qualcomm QCA61x4A 802.11ac Wireless Adapter
CreationClassName : Win32_NetworkAdapter
Description : Qualcomm QCA61x4A 802.11ac Wireless Adapter
DeviceID : 2
GUID : {8C8F81D9-434D-4436-BDC6-CB8E9B493CC2}
MACAddress : A8:93:4A:D5:4C:4B
Manufacturer : Qualcomm Communications Inc.
Name : Qualcomm QCA61x4A 802.11ac Wireless Adapter
NetConnectionID : WLAN
PNPDeviceID : PCI\VEN_168C&DEV_003E&SUBSYS_03101028&REV_32\4&166C4858&0&00E0
ProductName : Qualcomm QCA61x4A 802.11ac Wireless Adapter
ServiceName : Qcamain10x64
SystemCreationClassName : Win32_ComputerSystem
SystemName : LS-PRECISION356
Installed : true
ConfigManagerUserConfig : false
NetEnabled : true
PhysicalAdapter : true
PowerManagementSupported : false
AdapterTypeID : 0
Availability : 3
NetConnectionStatus : 2
ConfigManagerErrorCode : 0
Index : 2
InterfaceIndex : 18
MaxNumberControlled : 0
Speed : 130000000
TimeOfLastReset : 20240223091151.500000+480

network adapter info:
AdapterType : 以太网 802.3
Caption : [00000013] Intel(R) Ethernet Connection (14) I219-LM
CreationClassName : Win32_NetworkAdapter
Description : Intel(R) Ethernet Connection (14) I219-LM
DeviceID : 13
GUID : {3908C2F8-AECA-44A5-B21E-86168E851C84}
MACAddress : B4:45:06:61:4C:CB
Manufacturer : Intel
Name : Intel(R) Ethernet Connection (14) I219-LM
NetConnectionID : 以太网
PNPDeviceID : PCI\VEN_8086&DEV_15F9&SUBSYS_00008086&REV_11\3&11583659&0&FE
ProductName : Intel(R) Ethernet Connection (14) I219-LM
ServiceName : e1dexpress
SystemCreationClassName : Win32_ComputerSystem
SystemName : LS-PRECISION356
Installed : true
ConfigManagerUserConfig : false
NetEnabled : false
PhysicalAdapter : true
PowerManagementSupported : false
AdapterTypeID : 0
Availability : 3
NetConnectionStatus : 7
ConfigManagerErrorCode : 0
Index : 13
InterfaceIndex : 10
MaxNumberControlled : 0
Speed : 9223372036854775807
TimeOfLastReset : 20240223091151.500000+480

network adapter info:
AdapterType : 以太网 802.3
Caption : [00000015] Bluetooth Device (Personal Area Network)
CreationClassName : Win32_NetworkAdapter
Description : Bluetooth Device (Personal Area Network)
DeviceID : 15
GUID : {90BF2D7E-B249-4E6F-A4F4-5D0259DA872E}
MACAddress : A8:93:4A:D5:4C:4C
Manufacturer : Microsoft
Name : Bluetooth Device (Personal Area Network) #2
NetConnectionID : 蓝牙网络连接 2
PNPDeviceID : BTH\MS_BTHPAN\6&2BA96596&1&2
ProductName : Bluetooth Device (Personal Area Network)
ServiceName : BthPan
SystemCreationClassName : Win32_ComputerSystem
SystemName : LS-PRECISION356
Installed : true
ConfigManagerUserConfig : false
NetEnabled : false
PhysicalAdapter : true
PowerManagementSupported : false
AdapterTypeID : 0
Availability : 3
NetConnectionStatus : 7
ConfigManagerErrorCode : 0
Index : 15
InterfaceIndex : 19
MaxNumberControlled : 0
Speed : 3000000
TimeOfLastReset : 20240223091151.500000+480

请按任意键继续. . .

测试工程结构

在这里插入图片描述

实现

main.cpp

/*!
* \file main.cpp
* \brief 用WMI取计算机信息
* 固定磁盘信息(排除可移动磁盘)
* 网卡信息
*/ 

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <iostream>

#include "CDiskInfo.h"
#include "CNetworkAdapterInfo.h"

// COM初始化和反初始化在进程中只能进行一次
bool ComInitOnce();
void ComUnInitOnce();

int main()
{
    CDiskInfo* pInfoDisk = NULL;
    CNetworkAdapterInfo* pInfoNet = NULL;

    std::wstring strInfo;

    std::locale::global(std::locale("zh_cn"));

    do {
        if (!ComInitOnce())
        {
            break;
        }

        pInfoDisk = new CDiskInfo;
        if (NULL == pInfoDisk)
        {
            break;
        }

        if (!pInfoDisk->init())
        {
            break;
        }

        if (!pInfoDisk->get_info())
        {
            break;
        }

        pInfoNet = new CNetworkAdapterInfo;
        if (NULL == pInfoNet)
        {
            break;
        }

        if (!pInfoNet->init())
        {
            break;
        }

        if (!pInfoNet->get_info())
        {
            break;
        }

    } while (false);


    if (NULL != pInfoDisk)
    {
        delete pInfoDisk;
        pInfoDisk = NULL;
    }

    if (NULL != pInfoNet)
    {
        delete pInfoNet;
        pInfoNet = NULL;
    }    
    
    ComUnInitOnce();

    std::locale::global(std::locale("en_us"));
    system("pause");
}

bool ComInitOnce()
{
    bool b_COM_env_init_ok = false;
    HRESULT res;

    do {
        res = CoInitializeEx(NULL, COINIT_MULTITHREADED);
        if (!SUCCEEDED(res))
        {
            break;
        }

        res = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
        if (!SUCCEEDED(res))
        {
            break;
        }

        b_COM_env_init_ok = true;
    } while (false);

    return b_COM_env_init_ok;
}

void ComUnInitOnce()
{
    CoUninitialize();
}

CWmiBase.h

/*!
	\file CWmiBase.h
*/

#ifndef __CWMIBASE_H__
#define __CWMIBASE_H__

#include <WbemIdl.h>
#pragma comment(lib, "wbemuuid.lib")

#include <comdef.h>
#include <string> // for std:wstring

class CWmiBase
{
public:
	CWmiBase();
	virtual ~CWmiBase();

public:
	virtual bool get_info() = 0;
	bool init();

protected:
	bool execute_query(const std::wstring& query);

	bool getObjVauleByName_bool(IWbemClassObject* obj, const TCHAR* pszName, bool& val);
	bool getObjVauleByName_uint16(IWbemClassObject* obj, const TCHAR* pszName, uint16_t& val);
	bool getObjVauleByName_uint32(IWbemClassObject* obj, const TCHAR* pszName, uint32_t& val);
	bool getObjVauleByName_uint64(IWbemClassObject* obj, const TCHAR* pszName, uint64_t& val);
	bool getObjVauleByName_bstr(IWbemClassObject* obj, const TCHAR* pszName, std::wstring& val);
	bool getObjVauleByName_datetime(IWbemClassObject* obj, const TCHAR* pszName, std::wstring& val);

private:
	bool getObjVauleByName_var(IWbemClassObject* obj, const TCHAR* pszName, VARIANT& vt_prop);

protected:
	IWbemLocator* locator;
	IWbemServices* service;
	IEnumWbemClassObject* enumerator;
	bool b_COM_env_init_ok;
};

#endif // #ifndef __CWMIBASE_H__

CDiskInfo.h

/*!
* \file CDiskInfo.h
*/

#ifndef __CDISKINFO_H__
#define __CDISKINFO_H__

#include "CWmiBase.h"

class CDiskInfo : public CWmiBase
{
public:
	CDiskInfo();
	virtual ~CDiskInfo();
	
	virtual bool get_info();
};

#endif // #ifndef __CDISKINFO_H__

CNetworkAdapterInfo.h

/*!
 \file CNetworkAdapterInfo.h
*/

#ifndef __CNETWORKADAPTERINFO_H__
#define __CNETWORKADAPTERINFO_H__

#include "CWmiBase.h"

class CNetworkAdapterInfo : public CWmiBase
{
public:
	CNetworkAdapterInfo();
	virtual ~CNetworkAdapterInfo();

	virtual bool get_info();
};

#endif // __CNETWORKADAPTERINFO_H__

CWmiBase.cpp

#include "CWmiBase.h"

CWmiBase::CWmiBase() {
	locator = NULL;
	service = NULL;
	enumerator = NULL;
}

CWmiBase::~CWmiBase() {
	if (locator) {
		locator->Release();
	}

	if (service) {
		service->Release();
	}
}

bool CWmiBase::init()
{
	bool b_rc = false;
	HRESULT res;

	do {
		res = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID*)&locator);
		if (!SUCCEEDED(res) || (NULL == locator))
		{
			break;
		}

		res = locator->ConnectServer(_bstr_t("ROOT\\CIMV2"), nullptr, nullptr, nullptr, 0, nullptr, nullptr, &service);
		if (!SUCCEEDED(res) || (NULL == service))
		{
			break;
		}

		res = CoSetProxyBlanket(service, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, nullptr, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_NONE);
		if (!SUCCEEDED(res))
		{
			break;
		}

		b_rc = true;
	} while (false);

	return b_rc;
}

bool CWmiBase::execute_query(const std::wstring& query) {
	bool b_rc = false;
	do {
		if (NULL == service) {
			break;
		}

		b_rc = SUCCEEDED(service->ExecQuery(bstr_t(L"WQL"), bstr_t(std::wstring(query.begin(), query.end()).c_str()), WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY, nullptr, &enumerator));
	} while (false);

	return b_rc;
}

bool CWmiBase::getObjVauleByName_var(IWbemClassObject* obj, const TCHAR* pszName, VARIANT& vt_prop)
{
	bool b_rc = false;
	HRESULT hr;

	do {
		if ((NULL == obj) || (NULL == pszName))
		{
			break;
		}

		hr = obj->Get(pszName, 0, &vt_prop, NULL, NULL);
		if (!SUCCEEDED(hr))
		{
			break;
		}

		// https://learn.microsoft.com/en-us/windows/win32/api/wtypes/ne-wtypes-varenum
		if ((VT_EMPTY == vt_prop.vt) || (VT_NULL == vt_prop.vt))
		{
			break;
		}

		b_rc = true;
	} while (false);

	return b_rc;
}

bool CWmiBase::getObjVauleByName_bool(IWbemClassObject* obj, const TCHAR* pszName, bool& val)
{
	bool b_rc = false;
	VARIANT vt_prop;

	do {
		val = false;
		if (!getObjVauleByName_var(obj, pszName, vt_prop))
		{
			break;
		}

		if (VT_BOOL != vt_prop.vt)
		{
			_ASSERT(FALSE);
			break;
		}

		val = vt_prop.boolVal;
		b_rc = true;
	} while (false);

	VariantClear(&vt_prop);
	return b_rc;
}

bool CWmiBase::getObjVauleByName_uint16(IWbemClassObject* obj, const TCHAR* pszName, uint16_t& val)
{
	bool b_rc = false;
	VARIANT vt_prop;

	do {
		val = 0;
		if (!getObjVauleByName_var(obj, pszName, vt_prop))
		{
			break;
		}

		if (VT_I4 != vt_prop.vt)
		{
			_ASSERT(FALSE);
			break;
		}

		val = vt_prop.uiVal;
		b_rc = true;
	} while (false);

	VariantClear(&vt_prop);
	return b_rc;
}

bool CWmiBase::getObjVauleByName_uint32(IWbemClassObject* obj, const TCHAR* pszName, uint32_t& val)
{
	bool b_rc = false;
	VARIANT vt_prop;

	do {
		val = 0;
		if (!getObjVauleByName_var(obj, pszName, vt_prop))
		{
			break;
		}

		if (VT_I4 != vt_prop.vt)
		{
			_ASSERT(FALSE);
			break;
		}

		val = vt_prop.ulVal;
		b_rc = true;
	} while (false);

	VariantClear(&vt_prop);
	return b_rc;
}

bool CWmiBase::getObjVauleByName_uint64(IWbemClassObject* obj, const TCHAR* pszName, uint64_t& val)
{
	bool b_rc = false;
	VARIANT vt_prop;

	do {
		val = 0;
		if (!getObjVauleByName_var(obj, pszName, vt_prop))
		{
			break;
		}

		if (VT_FILETIME != vt_prop.vt)
		{
			_ASSERT(FALSE);
			break;
		}

		val = vt_prop.ullVal;
		b_rc = true;
	} while (false);

	VariantClear(&vt_prop);
	return b_rc;
}

bool CWmiBase::getObjVauleByName_bstr(IWbemClassObject* obj, const TCHAR* pszName, std::wstring& val)
{
	bool b_rc = false;
	VARIANT vt_prop;

	do {
		val.clear();
		if (!getObjVauleByName_var(obj, pszName, vt_prop))
		{
			break;
		}

		if (VT_BSTR != vt_prop.vt)
		{
			_ASSERT(FALSE);
			break;
		}

		val = vt_prop.bstrVal;
		b_rc = true;
	} while (false);

	VariantClear(&vt_prop);
	return b_rc;
}

bool CWmiBase::getObjVauleByName_datetime(IWbemClassObject* obj, const TCHAR* pszName, std::wstring& val)
{
	bool b_rc = false;
	VARIANT vt_prop;

	do {
		if (!getObjVauleByName_var(obj, pszName, vt_prop))
		{
			break;
		}

		if (VT_FILETIME != vt_prop.vt)
		{
			_ASSERT(FALSE);
			break;
		}

		val = vt_prop.bstrVal;
		b_rc = true;
	} while (false);

	VariantClear(&vt_prop);
	return b_rc;
}


CDiskInfo.cpp

#include "CDiskInfo.h"
#include <tchar.h>

CDiskInfo::CDiskInfo()
{
}

CDiskInfo::~CDiskInfo()
{

}

bool CDiskInfo::get_info()
{
	// https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-diskdrive
	const std::wstring query_string(L"SELECT Model, Size, MediaType FROM Win32_DiskDrive");
	bool b_rc = false;

	ULONG u_return = 0;
	IWbemClassObject* obj = NULL;
	int disk_id = 0;
	VARIANT vt_prop;
	std::wstring strTmp;

	do {
		if (!execute_query(query_string)) {
			break;
		}

		while (enumerator) {
			enumerator->Next(WBEM_INFINITE, 1, &obj, &u_return);
			if ((0 == u_return) || (NULL == obj)) {
				break;
			}

			_tprintf(TEXT("disk info:\n"));

			// string   MediaType;
			if (getObjVauleByName_bstr(obj, L"MediaType", strTmp))
			{
				// 固定的磁盘类型为 "Fixed hard disk media"
				if (strTmp == TEXT("Fixed hard disk media"))
				{
					_tprintf(TEXT("%ws = %ws\n"), L"MediaType", strTmp.c_str());

					// string   Model;
					if (getObjVauleByName_bstr(obj, L"Model", strTmp))
					{
						_tprintf(TEXT("%ws = %ws\n"), L"Model", strTmp.c_str());
					}

					// uint64   Size; // 官方的这个类型不对, 实际是 VT_BSTR
					if (getObjVauleByName_bstr(obj, L"Size", strTmp))
					{
						_tprintf(TEXT("%ws = %ws\n"), L"Size", strTmp.c_str());
					}

					_tprintf(TEXT("\r\n"));
				}
			}

			VariantClear(&vt_prop);
			obj->Release();
		}

		b_rc = true;
	} while (false);

	return b_rc;
}

CNetworkAdapterInfo.cpp

/*!
 \file CNetworkAdapterInfo.cpp  
 */

#include <tchar.h>

#include "CNetworkAdapterInfo.h"

CNetworkAdapterInfo::CNetworkAdapterInfo()
{
}

CNetworkAdapterInfo::~CNetworkAdapterInfo()
{
}

bool CNetworkAdapterInfo::get_info()
{
	// https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-networkadapter

	const std::wstring query_string(L"SELECT * FROM Win32_NetworkAdapter");
	bool b_rc = false;

	ULONG u_return = 0;
	IWbemClassObject* obj = NULL;
	int disk_id = 0;
	std::wstring strTmp;
	uint16_t u16_tmp = 0;
	uint32_t u32_tmp = 0;
	uint64_t u64_tmp = 0;
	bool b_tmp = false;

	do {
		if (!execute_query(query_string)) {
			break;
		}

		while (enumerator) {
			enumerator->Next(WBEM_INFINITE, 1, &obj, &u_return);
			if ((0 == u_return) || (NULL == obj)) {
				break;
			}

			// 只查找物理网卡
			// 物理网卡都有GUID
			
			//string   GUID;
			if (!getObjVauleByName_bstr(obj, TEXT("GUID"), strTmp))
			{
				continue;
			}

			// 物理网卡的PNPDeviceID属于以下类
			// PCI卡 e.g. PCI\VEN_168C&DEV_003E&SUBSYS_03101028&REV_32\4&166C4858&0&00E0
			// 蓝牙卡 BTH\MS_BTHPAN\6&2BA96596&1&2
			// 其他网卡类型都是虚拟网卡或驱动模拟的网卡

			//string   PNPDeviceID;
			if (!getObjVauleByName_bstr(obj, TEXT("PNPDeviceID"), strTmp))
			{
				continue;
			}

			// 0 != strTmp.compare(0, 4, TEXT("PCI\\")
			if ((strTmp.length() < 4) || ((0 != strTmp.compare(0, 4, TEXT("PCI\\"))) && (0 != strTmp.compare(0, 4, TEXT("BTH\\"))) ) )
			{
				continue;
			}


			_tprintf(TEXT("network adapter info:\r\n"));

			//string   AdapterType;
			if (getObjVauleByName_bstr(obj, TEXT("AdapterType"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("AdapterType"), strTmp.c_str());
			}

			//string   Caption;
			if (getObjVauleByName_bstr(obj, TEXT("Caption"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("Caption"), strTmp.c_str());
			}

			//string   CreationClassName;
			if (getObjVauleByName_bstr(obj, TEXT("CreationClassName"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("CreationClassName"), strTmp.c_str());
			}

			//string   Description;
			if (getObjVauleByName_bstr(obj, TEXT("Description"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("Description"), strTmp.c_str());
			}

			//string   DeviceID;
			if (getObjVauleByName_bstr(obj, TEXT("DeviceID"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("DeviceID"), strTmp.c_str());
			}

			//string   ErrorDescription;
			if (getObjVauleByName_bstr(obj, TEXT("ErrorDescription"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("ErrorDescription"), strTmp.c_str());
			}

			//string   GUID;
			if (getObjVauleByName_bstr(obj, TEXT("GUID"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("GUID"), strTmp.c_str());
			}

			//string   MACAddress;
			if (getObjVauleByName_bstr(obj, TEXT("MACAddress"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("MACAddress"), strTmp.c_str());
			}

			//string   Manufacturer;
			if (getObjVauleByName_bstr(obj, TEXT("Manufacturer"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("Manufacturer"), strTmp.c_str());
			}

			//string   Name;
			if (getObjVauleByName_bstr(obj, TEXT("Name"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("Name"), strTmp.c_str());
			}

			//string   NetConnectionID;
			if (getObjVauleByName_bstr(obj, TEXT("NetConnectionID"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("NetConnectionID"), strTmp.c_str());
			}

			//string   NetworkAddresses[];
			if (getObjVauleByName_bstr(obj, TEXT("NetworkAddresses"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("NetworkAddresses"), strTmp.c_str());
			}

			//string   PermanentAddress;
			if (getObjVauleByName_bstr(obj, TEXT("PermanentAddress"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("PermanentAddress"), strTmp.c_str());
			}

			//string   PNPDeviceID;
			if (getObjVauleByName_bstr(obj, TEXT("PNPDeviceID"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("PNPDeviceID"), strTmp.c_str());
			}

			//string   ProductName;
			if (getObjVauleByName_bstr(obj, TEXT("ProductName"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("ProductName"), strTmp.c_str());
			}

			//string   ServiceName;
			if (getObjVauleByName_bstr(obj, TEXT("ServiceName"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("ServiceName"), strTmp.c_str());
			}

			//string   Status;
			if (getObjVauleByName_bstr(obj, TEXT("Status"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("Status"), strTmp.c_str());
			}

			//string   SystemCreationClassName;
			if (getObjVauleByName_bstr(obj, TEXT("SystemCreationClassName"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("SystemCreationClassName"), strTmp.c_str());
			}

			//string   SystemName;
			if (getObjVauleByName_bstr(obj, TEXT("SystemName"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("SystemName"), strTmp.c_str());
			}

			//boolean  Installed;
			if (getObjVauleByName_bool(obj, TEXT("Installed"), b_tmp))
			{
				// wprintf时的字符串, 都用宽字符串, 否则英文也乱码
				_tprintf(TEXT("%ws : %ws\n"), TEXT("Installed"), (b_tmp ? TEXT("true") : TEXT("false")));
			}

			//boolean  AutoSense;
			if (getObjVauleByName_bool(obj, TEXT("AutoSense"), b_tmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("AutoSense"), (b_tmp ? TEXT("true") : TEXT("false")));
			}

			//boolean  ConfigManagerUserConfig;
			if (getObjVauleByName_bool(obj, TEXT("ConfigManagerUserConfig"), b_tmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("ConfigManagerUserConfig"), (b_tmp ? TEXT("true") : TEXT("false")));
			}

			//boolean  ErrorCleared;
			if (getObjVauleByName_bool(obj, TEXT("ErrorCleared"), b_tmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("ErrorCleared"), (b_tmp ? TEXT("true") : TEXT("false")));
			}

			//boolean  NetEnabled;
			if (getObjVauleByName_bool(obj, TEXT("NetEnabled"), b_tmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("NetEnabled"), (b_tmp ? TEXT("true") : TEXT("false")));
			}

			//boolean  PhysicalAdapter;
			if (getObjVauleByName_bool(obj, TEXT("PhysicalAdapter"), b_tmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("PhysicalAdapter"), (b_tmp ? TEXT("true") : TEXT("false")));
			}

			//boolean  PowerManagementSupported;
			if (getObjVauleByName_bool(obj, TEXT("PowerManagementSupported"), b_tmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("PowerManagementSupported"), (b_tmp ? TEXT("true") : TEXT("false")));
			}

			//uint16   AdapterTypeID;
			if (getObjVauleByName_uint16(obj, TEXT("AdapterTypeID"), u16_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("AdapterTypeID"), u16_tmp);
			}

			//uint16   Availability;
			if (getObjVauleByName_uint16(obj, TEXT("Availability"), u16_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("Availability"), u16_tmp);
			}

			//uint16   NetConnectionStatus;
			if (getObjVauleByName_uint16(obj, TEXT("NetConnectionStatus"), u16_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("NetConnectionStatus"), u16_tmp);
			}

			//uint16   PowerManagementCapabilities[];
			if (getObjVauleByName_uint16(obj, TEXT("PowerManagementCapabilities"), u16_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("PowerManagementCapabilities"), u16_tmp);
			}

			//uint16   StatusInfo;
			if (getObjVauleByName_uint16(obj, TEXT("StatusInfo"), u16_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("StatusInfo"), u16_tmp);
			}

			//uint32   ConfigManagerErrorCode;
			if (getObjVauleByName_uint32(obj, TEXT("ConfigManagerErrorCode"), u32_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("ConfigManagerErrorCode"), u32_tmp);
			}

			//uint32   Index;
			if (getObjVauleByName_uint32(obj, TEXT("Index"), u32_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("Index"), u32_tmp);
			}

			//uint32   InterfaceIndex;
			if (getObjVauleByName_uint32(obj, TEXT("InterfaceIndex"), u32_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("InterfaceIndex"), u32_tmp);
			}

			//uint32   LastErrorCode;
			if (getObjVauleByName_uint32(obj, TEXT("LastErrorCode"), u32_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("LastErrorCode"), u32_tmp);
			}

			//uint32   MaxNumberControlled;			
			if (getObjVauleByName_uint32(obj, TEXT("MaxNumberControlled"), u32_tmp))
			{
				_tprintf(TEXT("%ws : %u\n"), TEXT("MaxNumberControlled"), u32_tmp);
			}

			//uint64   MaxSpeed; 官方文档错了, 是bstr
			if (getObjVauleByName_bstr(obj, TEXT("MaxSpeed"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("MaxSpeed"), strTmp.c_str());
			}

			//uint64   Speed; 官方文档错了, 是bstr
			if (getObjVauleByName_bstr(obj, TEXT("Speed"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("Speed"), strTmp.c_str());
			}

			//datetime InstallDate;
			if (getObjVauleByName_bstr(obj, TEXT("InstallDate"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("InstallDate"), strTmp.c_str());
			}

			//datetime TimeOfLastReset;
			if (getObjVauleByName_bstr(obj, TEXT("TimeOfLastReset"), strTmp))
			{
				_tprintf(TEXT("%ws : %ws\n"), TEXT("TimeOfLastReset"), strTmp.c_str());
			}

			obj->Release();

			_tprintf(TEXT("\r\n"));
		}

		b_rc = true;
	} while (false);

	return b_rc;
}


END

Logo

DAMO开发者矩阵,由阿里巴巴达摩院和中国互联网协会联合发起,致力于探讨最前沿的技术趋势与应用成果,搭建高质量的交流与分享平台,推动技术创新与产业应用链接,围绕“人工智能与新型计算”构建开放共享的开发者生态。

更多推荐