Esempio n. 1
0
        /// <summary>
        /// 获取未知设备信息
        /// </summary>
        /// <param name="DeviceIndex"></param>
        /// <param name="ClassName"></param>
        /// <param name="DeviceName"></param>
        /// <returns></returns>
        public static int EnumerateDevices(List <string> NameList, List <string> IDList, List <string> MfgList, List <string> TypeList, List <string> IsInstallDriversList)
        {
            Guid   myGUID   = System.Guid.Empty;
            IntPtr hDevInfo = SetupDiGetClassDevsA(ref myGUID, 0, IntPtr.Zero, DIGCF_ALLCLASSES);

            if (hDevInfo.ToInt32() == -1)
            {
                //设备不可用

                return(-3);
            }
            SP_DEVINFO_DATA DeviceInfoData = new SP_DEVINFO_DATA();

            DeviceInfoData.cbSize = 28;
            //正常状态
            DeviceInfoData.DevInst   = 0;
            DeviceInfoData.ClassGuid = System.Guid.Empty;
            DeviceInfoData.Reserved  = 0;
            UInt32 i;

            for (i = 0; SetupDiEnumDeviceInfo(hDevInfo, i, DeviceInfoData); i++)
            {
                //设备名称
                StringBuilder DeviceName = new StringBuilder("");
                //设备ID
                StringBuilder DeviceID = new StringBuilder("");
                //设备供应商
                StringBuilder Mfg = new StringBuilder("");
                //设备类型
                StringBuilder DeviceType = new StringBuilder("");
                //设备类型
                StringBuilder IsInstallDrivers = new StringBuilder("");
                DeviceName.Capacity       = MAX_DEV_LEN;
                DeviceID.Capacity         = MAX_DEV_LEN;
                DeviceType.Capacity       = MAX_DEV_LEN;
                Mfg.Capacity              = MAX_DEV_LEN;
                IsInstallDrivers.Capacity = MAX_DEV_LEN;
                bool resName = SetupDiGetDeviceRegistryPropertyA(hDevInfo, DeviceInfoData, SPDRP_DEVICEDESC, 0, DeviceName, MAX_DEV_LEN, IntPtr.Zero);
                if (!resName)
                {
                    //设备名称未知
                    DeviceName = new StringBuilder("");
                }
                bool resClass = SetupDiGetDeviceRegistryPropertyA(hDevInfo, DeviceInfoData, SPDRP_CLASS, 0, DeviceType, MAX_DEV_LEN, IntPtr.Zero);
                if (!resClass)
                {
                    //设备类型未知
                    DeviceType = new StringBuilder("");
                }
                //设备ID
                bool resHardwareID = SetupDiGetDeviceRegistryPropertyA(hDevInfo,
                                                                       DeviceInfoData, SPDRP_HARDWAREID, 0, DeviceID, MAX_DEV_LEN, IntPtr.Zero);
                if (!resHardwareID)
                {
                    //设备ID未知
                    DeviceID = new StringBuilder("");
                }

                //设备供应商
                bool resMfg = SetupDiGetDeviceRegistryPropertyA(hDevInfo,
                                                                DeviceInfoData, SPDRP_MFG, 0, Mfg, MAX_DEV_LEN, IntPtr.Zero);
                if (!resMfg)
                {
                    //设备供应商未知
                    Mfg = new StringBuilder("");
                }

                bool resIsInstallDrivers = SetupDiGetDeviceRegistryPropertyA(hDevInfo,
                                                                             DeviceInfoData, SPDRP_DRIVER, 0, IsInstallDrivers, MAX_DEV_LEN, IntPtr.Zero);
                if (!resIsInstallDrivers)
                {
                    //设备是否安装驱动
                    IsInstallDrivers = new StringBuilder("");
                }

                if (string.IsNullOrEmpty(DeviceType.ToString()))
                {
                    if (!string.IsNullOrEmpty(DeviceName.ToString()) && !string.IsNullOrEmpty(DeviceID.ToString()))
                    {
                        TypeList.Add("其它设备");
                        NameList.Add(DeviceName.ToString());
                        IDList.Add(DeviceID.ToString());
                        MfgList.Add(Mfg.ToString());
                        IsInstallDriversList.Add(IsInstallDrivers.ToString());
                    }
                }
            }
            //释放当前设备占用内存
            SetupDiDestroyDeviceInfoList(hDevInfo);
            return(0);
        }
Esempio n. 2
0
 partial void UpdateMfg(Mfg instance);
Esempio n. 3
0
 partial void DeleteMfg(Mfg instance);
Esempio n. 4
0
 partial void InsertMfg(Mfg instance);