Пример #1
0
        public static void GetDeviceNames(Guid guid)
        {
            IntPtr hdi = SetupAPI.SetupDiGetClassDevsW(ref guid, null, IntPtr.Zero, SetupAPI.DIGCF_PRESENT);

            SetupAPI.SP_DEVINFO_DATA devInfoData = new SetupAPI.SP_DEVINFO_DATA();
            devInfoData.cbSize = Marshal.SizeOf(devInfoData);
            int i = 0;

            while (SetupAPI.SetupDiEnumDeviceInfo(hdi, i, ref devInfoData))
            {
                i++;
                String hwid = GetDeviceInfo(hdi, devInfoData, SetupAPI.SPDRP_HARDWAREID);
                if (hwid.StartsWith("BTHLE\\Dev_"))
                {
                    String friendlyName   = GetDeviceInfo(hdi, devInfoData, SetupAPI.SPDRP_FRIENDLYNAME);
                    String deviceDesc     = GetDeviceInfo(hdi, devInfoData, SetupAPI.SPDRP_DEVICEDESC);
                    String enumeratorName = GetDeviceInfo(hdi, devInfoData, SetupAPI.SPDRP_ENUMERATOR_NAME);
                    String status         = GetConnectedStatus(hdi, devInfoData) ? "connected" : "paired";
                    Console.WriteLine("hwid: {0}\nfriendlyName: {1}\ndeviceDesc: {2}\nenumeratorName: {3}\nstatus: {4}\n\n", hwid, friendlyName, deviceDesc, enumeratorName, status);
                }
            }
        }
Пример #2
0
        public static void GetDevInfo(Guid guid)
        {
            IntPtr hdi = SetupAPI.SetupDiGetClassDevsW(ref guid, null, IntPtr.Zero, SetupAPI.DIGCF_PRESENT | SetupAPI.DIGCF_DEVINTERFACE);

            Console.WriteLine(hdi);
            SetupAPI.SP_DEVINFO_DATA dd = new SetupAPI.SP_DEVINFO_DATA();
            dd.cbSize = Marshal.SizeOf(dd);
            SetupAPI.SP_DEVICE_INTERFACE_DATA did = new SetupAPI.SP_DEVICE_INTERFACE_DATA();
            did.cbSize = Marshal.SizeOf(did);
            int i = 0;

            while (SetupAPI.SetupDiEnumDeviceInterfaces(hdi, IntPtr.Zero, ref guid, i, ref did))
            {
                i += 1;
                SetupAPI.SP_DEVICE_INTERFACE_DETAIL_DATA didd = new SetupAPI.SP_DEVICE_INTERFACE_DETAIL_DATA();
                didd.cbSize = IntPtr.Size == 8 ? 8 : 4 + Marshal.SystemDefaultCharSize;
                UInt32 nRequiredSize = 0;
                SetupAPI.SetupDiGetDeviceInterfaceDetailW(hdi, ref did, ref didd, 256, ref nRequiredSize, ref dd);
                Console.WriteLine(didd.DevicePath);
                Communication(didd.DevicePath);
            }
            Console.WriteLine("\n\n");
        }