return (status & DN_NO_SHOW_IN_DM) != 0;
#pragma comment(lib, "setupapi.lib") #pragma comment(lib, "CfgMgr32.lib")
SP_DEVINFO_DATA devInfoData; devInfoData.cbSize = sizeof(SP_DEVINFO_DATA); DWORD idx = 0; int removed = 0; DeviceCleanup.exe
bool IsNonPresentDevice(DEVINST devInst) ULONG status = 0, problem = 0; if (CM_Get_DevNode_Status(&status, &problem, devInst, 0) != CR_SUCCESS) return true; // Cannot query status -> treat as problematic
enum Action ACTION_LIST, ACTION_REMOVE_ONE, ACTION_REMOVE_ALL ; Action g_action = ACTION_LIST; std::wstring g_targetId; bool g_force = false; bool g_verbose = false; return (status & DN_NO_SHOW_IN_DM)
SetupDiDestroyDeviceInfoList(hDevInfo); std::wcout << L"Removed " << removed << L" non-present device(s).\n"; return 0;
if (!matches && g_verbose) DWORD hwIdSize = 0; SetupDiGetDeviceRegistryProperty(hDevInfo, &devInfoData, SPDRP_HARDWAREID, NULL, NULL, 0, &hwIdSize); if (hwIdSize > 0) std::vector<BYTE> buffer(hwIdSize); SetupDiGetDeviceRegistryProperty(hDevInfo, &devInfoData, SPDRP_HARDWAREID, NULL, buffer.data(), hwIdSize, &hwIdSize); WCHAR* hwid = (WCHAR*)buffer.data(); while (*hwid) if (id == hwid) matches = true; break; hwid += wcslen(hwid) + 1; return (status & DN_NO_SHOW_IN_DM) != 0
while (SetupDiEnumDeviceInfo(hDevInfo, idx++, &devInfoData)) DEVINST devInst = devInfoData.DevInst;