windows中,如何读取驱动程序列表


需要查询一台电脑上安装的所有驱动程序,能想办法列出来吗(用C++或者C#实现)?
或者是使用cmd工具查询出来也可以,但不清楚有没有这方面的工具或者脚本。



相关链接

驱动 windows

单边马尾D控 10 years, 3 months ago
   
  void CDeviceScan::EnumAllDevices()
  
{
HDEVINFO hDevInfo = 0L;
SP_DEVINFO_DATA spDevInfoData = {0};
short wIndex = 0;
TCHAR szSetupClass[MAX_PATH] = {0};
int wImageIdx = 0;

hDevInfo = SetupDiGetClassDevs(0L, 0L, NULL, DIGCF_PRESENT |
DIGCF_ALLCLASSES | DIGCF_PROFILE);
if (hDevInfo == (void*)-1)
{
return;
}

wIndex = 0;
spDevInfoData.cbSize = sizeof(SP_DEVINFO_DATA);
while (1)
{
if (SetupDiEnumDeviceInfo(hDevInfo,
wIndex,
&spDevInfoData))
{
TCHAR szBuf[MAX_PATH] = {0};
short wItem = 0;

if (!SetupDiGetDeviceRegistryProperty(hDevInfo,
&spDevInfoData,
SPDRP_CLASS, //SPDRP_CLASS,
0L,
(PBYTE)szSetupClass,
MAX_PATH,
0))
{
wIndex++;
continue;
}

if (!IsInBlackList(szSetupClass))
{

if (SetupDiGetClassImageIndex(&m_spImageData,
&spDevInfoData.ClassGuid,
(int*)&wImageIdx))
{
TCHAR szName[128] = {0};
TCHAR szID[LINE_LEN] = {0};
TCHAR szPath[MAX_PATH] = {0};
DWORD dwRequireSize;
short wOrder;

if (!SetupDiGetClassDescription(&spDevInfoData.ClassGuid,
szBuf,
MAX_PATH,
&dwRequireSize))
{

wIndex++;
continue;
}

wOrder = FindDeviceOrder(szBuf);
if (!AddNewDeviceOrderNode(szBuf, wImageIdx))
{
wIndex++;
continue;
}

GetDeviceInstanceID(hDevInfo, &spDevInfoData, szID);
GetDeviceInterfaceInfo(hDevInfo, spDevInfoData, szPath);

if (SetupDiGetDeviceRegistryProperty(hDevInfo,
&spDevInfoData,
SPDRP_FRIENDLYNAME,
0L,
(PBYTE)szName,
127,
0))
{
AddNewDeviceNode(spDevInfoData.ClassGuid, szName, szID, szPath, wIndex, wImageIdx, wOrder, szSetupClass,szBuf);
}
else if (SetupDiGetDeviceRegistryProperty(hDevInfo,
&spDevInfoData,
SPDRP_DEVICEDESC,
0L,
(PBYTE)szName,
127,
0))
{
AddNewDeviceNode(spDevInfoData.ClassGuid, szName, szID, szPath, wIndex, wImageIdx, wOrder, szSetupClass,szBuf);
}
else
{
DWORD dError = GetLastError();
}
}
}
}
else
{
DWORD dError = GetLastError();
break;
}
wIndex++;
}

SetupDiDestroyDeviceInfoList(hDevInfo);

天衣無縫D亡靈 answered 10 years, 3 months ago

Your Answer