gpt4 book ai didi

c++ - 如何在 Windows 设备管理器中获取带有黄色感叹号的设备列表 - C++

转载 作者:可可西里 更新时间:2023-11-01 10:39:02 25 4
gpt4 key购买 nike

我正在使用 msdn WMI 示例代码来获取设备管理器中显示的带有黄色感叹号的设备列表,但它只返回所有正确的列表机器上安装的设备。这里的任何人都可以帮助我仅使用 C++ 解决这个问题。谢谢

    void GetUnKnownDeviceList()
{
HRESULT hres;
hres = CoInitializeEx(0, COINIT_MULTITHREADED);

hres = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_DEFAULT,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);

IWbemLocator *pLoc = 0;
hres = CoCreateInstance( CLSID_WbemLocator, 0, CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) &pLoc);
IWbemServices *pSvc = 0;

hres = pLoc->ConnectServer(_bstr_t(L"ROOT\\CIMV2"),NULL,NULL,0,NULL,0,0,&pSvc);

hres = CoSetProxyBlanket(pSvc, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL, RPC_C_AUTHN_LEVEL_CALL,
RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE);

IEnumWbemClassObject* pEnumerator = NULL;
hres = pSvc->ExecQuery(
bstr_t("WQL"),
// bstr_t("SELECT * FROM Win32_PnPEntity"), DOES NOT LIST DEVICES SHOWING WITH YELLOW EXCLAMATION MARK
bstr_t("SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode = 0"), // LIST ONLY PROPERLY INSTALLED DEVICES
WBEM_FLAG_FORWARD_ONLY | WBEM_FLAG_RETURN_IMMEDIATELY,
NULL,
&pEnumerator);

IWbemClassObject *pclsObj;
ULONG uReturn = 0;
while(1)
{
HRESULT hr = pEnumerator->Next(WBEM_INFINITE, 1, &pclsObj, &uReturn);
VARIANT vtProp;
hr = pclsObj->Get(L"Name", 0, &vtProp, 0, 0);
TRACE("Device Name : %s\r\n\", vtProp.bstrVal);
VariantClear(&vtProp);
pclsObj->Release();
}

}

最佳答案

要列出不工作的设备,您需要查询 ConfigManagerErrrorCode 不是 0 的所有设备,您必须将 WQL 语句修改为。

SELECT * FROM Win32_PnPEntity WHERE ConfigManagerErrorCode <> 0

关于c++ - 如何在 Windows 设备管理器中获取带有黄色感叹号的设备列表 - C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9325261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com