예제 #1
0
        private static string GetDriverProperty(string searchHardwareId,
                                                NativeMethods.DEVPROPKEY prop)
        {
            string result   = "";
            bool   devmatch = false;
            Guid   sysGuid  = Guid.Parse("{4d36e97d-e325-11ce-bfc1-08002be10318}");

            NativeMethods.SP_DEVINFO_DATA deviceInfoData = new NativeMethods.SP_DEVINFO_DATA();
            deviceInfoData.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(deviceInfoData);
            var   dataBuffer   = new byte[4096];
            ulong propertyType = 0;
            var   requiredSize = 0;
            //var type = 0;
            IntPtr deviceInfoSet = NativeMethods.SetupDiGetClassDevs(ref sysGuid, null, 0, 0);

            for (int i = 0; !devmatch && NativeMethods.SetupDiEnumDeviceInfo(deviceInfoSet, i, ref deviceInfoData); i++)
            {
                if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref NativeMethods.DEVPKEY_Device_HardwareIds, ref propertyType,
                                                           dataBuffer, dataBuffer.Length, ref requiredSize, 0))
                {
                    string hardwareId = dataBuffer.ToUTF16String();
                    if (hardwareId.Equals(searchHardwareId))
                    {
                        devmatch = true;
                    }
                }
            }

            if (devmatch)
            {
                if (NativeMethods.SetupDiGetDeviceProperty(deviceInfoSet, ref deviceInfoData, ref prop, ref propertyType,
                                                           dataBuffer, dataBuffer.Length, ref requiredSize, 0))
                {
                    result = dataBuffer.ToUTF16String();
                }
            }

            if (deviceInfoSet.ToInt64() != NativeMethods.INVALID_HANDLE_VALUE)
            {
                NativeMethods.SetupDiDestroyDeviceInfoList(deviceInfoSet);
            }

            return(result);
        }
예제 #2
0
 public static string HidGuardDevProp(NativeMethods.DEVPROPKEY prop)
 {
     return(GetDriverProperty(hidGuardDevicePath, prop));
 }