64,637
社区成员
发帖
与我相关
我的任务
分享
#include <Windows.h>
#include <initguid.h>
#include <devpkey.h>
#include <cfgmgr32.h>
#include <SetupAPI.h>
#pragma comment (lib, "setupapi.lib")
#include <iostream>
using namespace std;
int main()
{
HDEVINFO DeviceInfoSet = SetupDiGetClassDevsW(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return 0;
for (int i = 0; ; i++) {
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(DeviceInfoSet, i, &DeviceInfoData))
break;
DWORD RequiredSize = 0;
DEVPROPTYPE PropertyType = 0;
WCHAR PropertyBuffer[4096] = { 0 };
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_BusReportedDeviceDesc, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_LocationInfo, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
wcout << L" Device Location Info: \"" << PropertyBuffer << L"\"" << endl;
}
return 0;
}
[/quote]
#include <Windows.h>
#include <initguid.h>
#include <devpkey.h>
#include <cfgmgr32.h>
#include <SetupAPI.h>
#pragma comment (lib, "setupapi.lib")
#include <iostream>
using namespace std;
int main()
{
HDEVINFO DeviceInfoSet = SetupDiGetClassDevsW(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return 0;
for (int i = 0; ; i++) {
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(DeviceInfoSet, i, &DeviceInfoData))
break;
DWORD RequiredSize = 0;
DEVPROPTYPE PropertyType = 0;
WCHAR PropertyBuffer[4096] = { 0 };
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_BusReportedDeviceDesc, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_LocationInfo, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
wcout << L" Device Location Info: \"" << PropertyBuffer << L"\"" << endl;
}
return 0;
}
[/quote]
#include <Windows.h>
#include <initguid.h>
#include <devpkey.h>
#include <cfgmgr32.h>
#include <SetupAPI.h>
#pragma comment (lib, "setupapi.lib")
#include <iostream>
using namespace std;
int main()
{
HDEVINFO DeviceInfoSet = SetupDiGetClassDevsW(NULL, L"USB", NULL, DIGCF_ALLCLASSES | DIGCF_PRESENT);
if (DeviceInfoSet == INVALID_HANDLE_VALUE)
return 0;
for (int i = 0; ; i++) {
SP_DEVINFO_DATA DeviceInfoData;
DeviceInfoData.cbSize = sizeof(DeviceInfoData);
if (!SetupDiEnumDeviceInfo(DeviceInfoSet, i, &DeviceInfoData))
break;
DWORD RequiredSize = 0;
DEVPROPTYPE PropertyType = 0;
WCHAR PropertyBuffer[4096] = { 0 };
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_BusReportedDeviceDesc, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
if (SetupDiGetDevicePropertyW(DeviceInfoSet, &DeviceInfoData, &DEVPKEY_Device_LocationInfo, &PropertyType, reinterpret_cast<PBYTE>(PropertyBuffer), sizeof(PropertyBuffer), &RequiredSize, 0))
wcout << L" Device Location Info: \"" << PropertyBuffer << L"\"" << endl;
}
return 0;
}