public static ReadOnlyCollection <USBController> GetHostControllers() { List <USBController> list = new List <USBController>(); Guid guid = new Guid("3abf6f2d-71c4-462a-8a92-1e6861e6af27"); IntPtr deviceInfoSet = Acer_USB_Library.SetupDiGetClassDevs(ref guid, 0, IntPtr.Zero, 18); if (deviceInfoSet.ToInt32() != -1) { IntPtr intPtr = Marshal.AllocHGlobal(2048); int num = 0; bool flag; do { USBController uSBController = new USBController(); uSBController.ControllerIndex = num; SP_DEVICE_INTERFACE_DATA structure = default(SP_DEVICE_INTERFACE_DATA); structure.cbSize = Marshal.SizeOf(structure); flag = Acer_USB_Library.SetupDiEnumDeviceInterfaces(deviceInfoSet, IntPtr.Zero, ref guid, num, ref structure); if (flag) { SP_DEVINFO_DATA structure2 = default(SP_DEVINFO_DATA); structure2.cbSize = Marshal.SizeOf(structure2); SP_DEVICE_INTERFACE_DETAIL_DATA sP_DEVICE_INTERFACE_DETAIL_DATA = default(SP_DEVICE_INTERFACE_DETAIL_DATA); sP_DEVICE_INTERFACE_DETAIL_DATA.cbSize = 4 + Marshal.SystemDefaultCharSize; int num2 = 0; int deviceInterfaceDetailDataSize = 2048; if (Acer_USB_Library.SetupDiGetDeviceInterfaceDetail(deviceInfoSet, ref structure, ref sP_DEVICE_INTERFACE_DETAIL_DATA, deviceInterfaceDetailDataSize, ref num2, ref structure2)) { uSBController.ControllerDevicePath = sP_DEVICE_INTERFACE_DETAIL_DATA.DevicePath; int num3 = 0; int num4 = 1; if (Acer_USB_Library.SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref structure2, 0, ref num4, intPtr, 2048, ref num3)) { uSBController.ControllerDeviceDesc = Marshal.PtrToStringAuto(intPtr); } if (Acer_USB_Library.SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref structure2, 9, ref num4, intPtr, 2048, ref num3)) { uSBController.ControllerDriverKeyName = Marshal.PtrToStringAuto(intPtr); } } list.Add(uSBController); } num++; }while (flag); Marshal.FreeHGlobal(intPtr); Acer_USB_Library.SetupDiDestroyDeviceInfoList(deviceInfoSet); } return(new ReadOnlyCollection <USBController>(list)); }
private static string GetInstanceIDByKeyName(string DriverKeyName) { string result = ""; string enumerator = "USB"; IntPtr deviceInfoSet = Acer_USB_Library.SetupDiGetClassDevs(0, enumerator, IntPtr.Zero, 6); if (deviceInfoSet.ToInt32() != -1) { IntPtr intPtr = Marshal.AllocHGlobal(2048); int num = 0; bool flag; do { SP_DEVINFO_DATA structure = default(SP_DEVINFO_DATA); structure.cbSize = Marshal.SizeOf(structure); flag = Acer_USB_Library.SetupDiEnumDeviceInfo(deviceInfoSet, num, ref structure); if (flag) { int num2 = 0; int num3 = 1; string a = ""; if (Acer_USB_Library.SetupDiGetDeviceRegistryProperty(deviceInfoSet, ref structure, 9, ref num3, intPtr, 2048, ref num2)) { a = Marshal.PtrToStringAuto(intPtr); } if (a == DriverKeyName) { int num4 = 2048; StringBuilder stringBuilder = new StringBuilder(num4); Acer_USB_Library.SetupDiGetDeviceInstanceId(deviceInfoSet, ref structure, stringBuilder, num4, out num2); result = stringBuilder.ToString(); break; } } num++; }while (flag); Marshal.FreeHGlobal(intPtr); Acer_USB_Library.SetupDiDestroyDeviceInfoList(deviceInfoSet); } return(result); }