Win32_BaseBoard 的 WMI 查询未返回结果
以下通过 WMI 检索主板信息的 C++ 代码适用于除一台机器之外的大多数机器:
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("Select * from Win32_BaseBoard"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
// handle error, exit
}
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
hr = pclsObj->Get(L"Product", 0, &vtProp, 0, 0);
std::wstring productNo = vtProp.bstrVal;
// do stuff with productNo
}
具体来说,pEnumerator->Next()
返回 0,因此 pclsObj
保留为 NULL。
您是否遇到过 Win32_BaseBoard
上的 WMI 查询不返回任何条目的情况?
The following C++ code to retrieve the motherboard info via WMI works on most machines, except one:
IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
bstr_t("Select * from Win32_BaseBoard"),
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);
if (FAILED(hres))
{
// handle error, exit
}
IWbemClassObject *pclsObj = NULL;
ULONG uReturn = 0;
while (pEnumerator)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1,
&pclsObj, &uReturn);
if(0 == uReturn)
{
break;
}
VARIANT vtProp;
hr = pclsObj->Get(L"Product", 0, &vtProp, 0, 0);
std::wstring productNo = vtProp.bstrVal;
// do stuff with productNo
}
Specifically, pEnumerator->Next()
returns 0, and therefore pclsObj
is left NULL.
Have you ever run into a situation where a WMI query on Win32_BaseBoard
returns no entries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的 VirtualBox 虚拟机中干净的 Windows XP SP3 /w .NET Framework 2.0 计算机不会返回任何记录,如“wmic”工具所示:
因此,这似乎是正常情况,而不仅仅是孤立事件。 我会计划可能不会出现任何记录。
My clean Windows XP SP3 /w .NET Framework 2.0 machine in a VirtualBox virtual machine does not return any records, as indicated by the "wmic" tool:
So this appears to be a normal circumstance and not just an isolated incidence. I would plan on the possibility that no records may appear.