C#:基于WMI查询USB设备

来源:互联网 发布:微博淘宝企业版 编辑:程序博客网 时间:2024/04/29 09:31

作者:Splash

转自:http://blog.csdn.net/jhqin/article/details/6734673


[csharp] view plaincopy
  1. /* ---------------------------------------------------------- 
  2. 文件名称:WMIUsbQuery.cs 
  3.  
  4. 作者:秦建辉 
  5.  
  6. MSN:splashcn@msn.com 
  7. QQ:36748897 
  8.  
  9. 博客:http://blog.csdn.net/jhqin 
  10.  
  11. 开发环境: 
  12.     Visual Studio V2010 
  13.     .NET Framework 4 Client Profile 
  14.  
  15. 版本历史:     
  16.     V1.3    2011年09月08日     
  17.             代码优化 
  18.  
  19.     V1.2    2011年09月02日 
  20.             增加基于服务的查询 
  21.  
  22.     V1.1    2011年09月01日 
  23.             增加基于设备ID的查询,解决LIKE子句中反斜杠字符引发的WQL查询异常 
  24.  
  25.     V1.0    2011年08月30日 
  26.             基于WMI实现对USB设备的查询 
  27. ------------------------------------------------------------ */  
  28. using System;  
  29. using System.Management;  
  30. using System.Text.RegularExpressions;  
  31. using System.Collections.Generic;  
  32.   
  33. namespace Splash.IO.PORTS  
  34. {  
  35.     /// <summary>  
  36.     /// 即插即用设备信息结构  
  37.     /// </summary>  
  38.     public struct PnPEntityInfo  
  39.     {  
  40.         public String PNPDeviceID;      // 设备ID  
  41.         public String Name;             // 设备名称  
  42.         public String Description;      // 设备描述  
  43.         public String Service;          // 服务  
  44.         public String Status;           // 设备状态  
  45.         public UInt16 VendorID;         // 供应商标识  
  46.         public UInt16 ProductID;        // 产品编号   
  47.         public Guid ClassGuid;          // 设备安装类GUID  
  48.     }      
  49.   
  50.     /// <summary>  
  51.     /// 基于WMI获取USB设备信息  
  52.     /// </summary>  
  53.     public partial class USB  
  54.     {        
  55.         #region UsbDevice  
  56.         /// <summary>  
  57.         /// 获取所有的USB设备实体(过滤没有VID和PID的设备)  
  58.         /// </summary>  
  59.         public static PnPEntityInfo[] AllUsbDevices  
  60.         {  
  61.             get  
  62.             {  
  63.                 return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, Guid.Empty);  
  64.             }  
  65.         }  
  66.   
  67.         /// <summary>  
  68.         /// 查询USB设备实体(设备要求有VID和PID)  
  69.         /// </summary>  
  70.         /// <param name="VendorID">供应商标识,MinValue忽视</param>  
  71.         /// <param name="ProductID">产品编号,MinValue忽视</param>  
  72.         /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>  
  73.         /// <returns>设备列表</returns>  
  74.         public static PnPEntityInfo[] WhoUsbDevice(UInt16 VendorID, UInt16 ProductID, Guid ClassGuid)  
  75.         {  
  76.             List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();  
  77.   
  78.             // 获取USB控制器及其相关联的设备实体  
  79.             ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();  
  80.             if (USBControllerDeviceCollection != null)  
  81.             {  
  82.                 foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)  
  83.                 {   // 获取设备实体的DeviceID  
  84.                     String Dependent = (USBControllerDevice["Dependent"as String).Split(new Char[] { '=' })[1];  
  85.   
  86.                     // 过滤掉没有VID和PID的USB设备  
  87.                     Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");  
  88.                     if (match.Success)  
  89.                     {  
  90.                         UInt16 theVendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识  
  91.                         if (VendorID != UInt16.MinValue && VendorID != theVendorID) continue;  
  92.   
  93.                         UInt16 theProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号  
  94.                         if (ProductID != UInt16.MinValue && ProductID != theProductID) continue;  
  95.   
  96.                         ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();  
  97.                         if (PnPEntityCollection != null)  
  98.                         {  
  99.                             foreach (ManagementObject Entity in PnPEntityCollection)  
  100.                             {  
  101.                                 Guid theClassGuid = new Guid(Entity["ClassGuid"as String);    // 设备安装类GUID  
  102.                                 if (ClassGuid != Guid.Empty && ClassGuid != theClassGuid) continue;  
  103.   
  104.                                 PnPEntityInfo Element;  
  105.                                 Element.PNPDeviceID = Entity["PNPDeviceID"as String;  // 设备ID  
  106.                                 Element.Name = Entity["Name"as String;                // 设备名称  
  107.                                 Element.Description = Entity["Description"as String;  // 设备描述  
  108.                                 Element.Service = Entity["Service"as String;          // 服务  
  109.                                 Element.Status = Entity["Status"as String;            // 设备状态  
  110.                                 Element.VendorID = theVendorID;     // 供应商标识  
  111.                                 Element.ProductID = theProductID;   // 产品编号  
  112.                                 Element.ClassGuid = theClassGuid;   // 设备安装类GUID  
  113.   
  114.                                 UsbDevices.Add(Element);  
  115.                             }  
  116.                         }  
  117.                     }  
  118.                 }  
  119.             }  
  120.   
  121.             if (UsbDevices.Count == 0) return nullelse return UsbDevices.ToArray();  
  122.         }  
  123.   
  124.         /// <summary>  
  125.         /// 查询USB设备实体(设备要求有VID和PID)  
  126.         /// </summary>  
  127.         /// <param name="VendorID">供应商标识,MinValue忽视</param>  
  128.         /// <param name="ProductID">产品编号,MinValue忽视</param>  
  129.         /// <returns>设备列表</returns>  
  130.         public static PnPEntityInfo[] WhoUsbDevice(UInt16 VendorID, UInt16 ProductID)  
  131.         {  
  132.             return WhoUsbDevice(VendorID, ProductID, Guid.Empty);  
  133.         }  
  134.   
  135.         /// <summary>  
  136.         /// 查询USB设备实体(设备要求有VID和PID)  
  137.         /// </summary>  
  138.         /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>  
  139.         /// <returns>设备列表</returns>  
  140.         public static PnPEntityInfo[] WhoUsbDevice(Guid ClassGuid)  
  141.         {  
  142.             return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, ClassGuid);  
  143.         }  
  144.   
  145.         /// <summary>  
  146.         /// 查询USB设备实体(设备要求有VID和PID)  
  147.         /// </summary>  
  148.         /// <param name="PNPDeviceID">设备ID,可以是不完整信息</param>  
  149.         /// <returns>设备列表</returns>          
  150.         public static PnPEntityInfo[] WhoUsbDevice(String PNPDeviceID)  
  151.         {  
  152.             List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();  
  153.   
  154.             // 获取USB控制器及其相关联的设备实体  
  155.             ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();  
  156.             if (USBControllerDeviceCollection != null)  
  157.             {  
  158.                 foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)  
  159.                 {   // 获取设备实体的DeviceID  
  160.                     String Dependent = (USBControllerDevice["Dependent"as String).Split(new Char[] { '=' })[1];  
  161.                     if (!String.IsNullOrEmpty(PNPDeviceID))  
  162.                     {   // 注意:忽视大小写  
  163.                         if (Dependent.IndexOf(PNPDeviceID, 1, PNPDeviceID.Length - 2, StringComparison.OrdinalIgnoreCase) == -1) continue;  
  164.                     }  
  165.   
  166.                     // 过滤掉没有VID和PID的USB设备  
  167.                     Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");  
  168.                     if (match.Success)  
  169.                     {  
  170.                         ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();  
  171.                         if (PnPEntityCollection != null)  
  172.                         {                              
  173.                             foreach (ManagementObject Entity in PnPEntityCollection)  
  174.                             {  
  175.                                 PnPEntityInfo Element;  
  176.                                 Element.PNPDeviceID = Entity["PNPDeviceID"as String;  // 设备ID  
  177.                                 Element.Name = Entity["Name"as String;                // 设备名称  
  178.                                 Element.Description = Entity["Description"as String;  // 设备描述  
  179.                                 Element.Service = Entity["Service"as String;          // 服务  
  180.                                 Element.Status = Entity["Status"as String;            // 设备状态  
  181.                                 Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识     
  182.                                 Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号                         // 产品编号  
  183.                                 Element.ClassGuid = new Guid(Entity["ClassGuid"as String);            // 设备安装类GUID  
  184.   
  185.                                 UsbDevices.Add(Element);  
  186.                             }  
  187.                         }  
  188.                     }  
  189.                 }  
  190.             }  
  191.   
  192.             if (UsbDevices.Count == 0) return nullelse return UsbDevices.ToArray();  
  193.         }  
  194.   
  195.         /// <summary>  
  196.         /// 根据服务定位USB设备  
  197.         /// </summary>  
  198.         /// <param name="ServiceCollection">要查询的服务集合</param>  
  199.         /// <returns>设备列表</returns>  
  200.         public static PnPEntityInfo[] WhoUsbDevice(String[] ServiceCollection)  
  201.         {  
  202.             if (ServiceCollection == null || ServiceCollection.Length == 0)  
  203.                 return WhoUsbDevice(UInt16.MinValue, UInt16.MinValue, Guid.Empty);  
  204.   
  205.             List<PnPEntityInfo> UsbDevices = new List<PnPEntityInfo>();  
  206.   
  207.             // 获取USB控制器及其相关联的设备实体  
  208.             ManagementObjectCollection USBControllerDeviceCollection = new ManagementObjectSearcher("SELECT * FROM Win32_USBControllerDevice").Get();  
  209.             if (USBControllerDeviceCollection != null)  
  210.             {  
  211.                 foreach (ManagementObject USBControllerDevice in USBControllerDeviceCollection)  
  212.                 {   // 获取设备实体的DeviceID  
  213.                     String Dependent = (USBControllerDevice["Dependent"as String).Split(new Char[] { '=' })[1];                      
  214.   
  215.                     // 过滤掉没有VID和PID的USB设备  
  216.                     Match match = Regex.Match(Dependent, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");  
  217.                     if (match.Success)  
  218.                     {  
  219.                         ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE DeviceID=" + Dependent).Get();  
  220.                         if (PnPEntityCollection != null)  
  221.                         {  
  222.                             foreach (ManagementObject Entity in PnPEntityCollection)  
  223.                             {  
  224.                                 String theService = Entity["Service"as String;          // 服务  
  225.                                 if (String.IsNullOrEmpty(theService)) continue;  
  226.   
  227.                                 foreach (String Service in ServiceCollection)  
  228.                                 {   // 注意:忽视大小写  
  229.                                     if (String.Compare(theService, Service, true) != 0) continue;  
  230.   
  231.                                     PnPEntityInfo Element;  
  232.                                     Element.PNPDeviceID = Entity["PNPDeviceID"as String;  // 设备ID  
  233.                                     Element.Name = Entity["Name"as String;                // 设备名称  
  234.                                     Element.Description = Entity["Description"as String;  // 设备描述  
  235.                                     Element.Service = theService;                           // 服务  
  236.                                     Element.Status = Entity["Status"as String;            // 设备状态  
  237.                                     Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识     
  238.                                     Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号  
  239.                                     Element.ClassGuid = new Guid(Entity["ClassGuid"as String);            // 设备安装类GUID  
  240.   
  241.                                     UsbDevices.Add(Element);  
  242.                                     break;  
  243.                                 }  
  244.                             }  
  245.                         }  
  246.                     }  
  247.                 }  
  248.             }  
  249.   
  250.             if (UsbDevices.Count == 0) return nullelse return UsbDevices.ToArray();  
  251.         }  
  252.         #endregion  
  253.  
  254.         #region PnPEntity  
  255.         /// <summary>  
  256.         /// 所有即插即用设备实体(过滤没有VID和PID的设备)  
  257.         /// </summary>  
  258.         public static PnPEntityInfo[] AllPnPEntities  
  259.         {  
  260.             get  
  261.             {  
  262.                 return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, Guid.Empty);  
  263.             }  
  264.         }  
  265.   
  266.         /// <summary>  
  267.         /// 根据VID和PID及设备安装类GUID定位即插即用设备实体  
  268.         /// </summary>  
  269.         /// <param name="VendorID">供应商标识,MinValue忽视</param>  
  270.         /// <param name="ProductID">产品编号,MinValue忽视</param>  
  271.         /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>  
  272.         /// <returns>设备列表</returns>  
  273.         /// <remarks>  
  274.         /// HID:{745a17a0-74d3-11d0-b6fe-00a0c90f57da}  
  275.         /// Imaging Device:{6bdd1fc6-810f-11d0-bec7-08002be2092f}  
  276.         /// Keyboard:{4d36e96b-e325-11ce-bfc1-08002be10318}   
  277.         /// Mouse:{4d36e96f-e325-11ce-bfc1-08002be10318}  
  278.         /// Network Adapter:{4d36e972-e325-11ce-bfc1-08002be10318}  
  279.         /// USB:{36fc9e60-c465-11cf-8056-444553540000}  
  280.         /// </remarks>  
  281.         public static PnPEntityInfo[] WhoPnPEntity(UInt16 VendorID, UInt16 ProductID, Guid ClassGuid)  
  282.         {  
  283.             List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();  
  284.   
  285.             // 枚举即插即用设备实体  
  286.             String VIDPID;  
  287.             if (VendorID == UInt16.MinValue)  
  288.             {  
  289.                 if (ProductID == UInt16.MinValue)  
  290.                     VIDPID = "'%VID[_]____&PID[_]____%'";  
  291.                 else  
  292.                     VIDPID = "'%VID[_]____&PID[_]" + ProductID.ToString("X4") + "%'";         
  293.             }  
  294.             else  
  295.             {  
  296.                 if (ProductID == UInt16.MinValue)  
  297.                     VIDPID = "'%VID[_]" + VendorID.ToString("X4") + "&PID[_]____%'";  
  298.                 else  
  299.                     VIDPID = "'%VID[_]" + VendorID.ToString("X4") + "&PID[_]" + ProductID.ToString("X4") + "%'";  
  300.             }  
  301.   
  302.             String QueryString;  
  303.             if (ClassGuid == Guid.Empty)  
  304.                 QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE" + VIDPID;  
  305.             else  
  306.                 QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE" + VIDPID + " AND ClassGuid='" + ClassGuid.ToString("B") + "'";  
  307.   
  308.             ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();  
  309.             if (PnPEntityCollection != null)  
  310.             {  
  311.                 foreach (ManagementObject Entity in PnPEntityCollection)  
  312.                 {  
  313.                     String PNPDeviceID = Entity["PNPDeviceID"as String;  
  314.                     Match match = Regex.Match(PNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");  
  315.                     if (match.Success)  
  316.                     {  
  317.                         PnPEntityInfo Element;  
  318.   
  319.                         Element.PNPDeviceID = PNPDeviceID;                      // 设备ID  
  320.                         Element.Name = Entity["Name"as String;                // 设备名称  
  321.                         Element.Description = Entity["Description"as String;  // 设备描述  
  322.                         Element.Service = Entity["Service"as String;          // 服务  
  323.                         Element.Status = Entity["Status"as String;            // 设备状态  
  324.                         Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识  
  325.                         Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号  
  326.                         Element.ClassGuid = new Guid(Entity["ClassGuid"as String);            // 设备安装类GUID  
  327.   
  328.                         PnPEntities.Add(Element);  
  329.                     }  
  330.                 }  
  331.             }  
  332.   
  333.             if (PnPEntities.Count == 0) return nullelse return PnPEntities.ToArray();  
  334.         }    
  335.         
  336.         /// <summary>  
  337.         /// 根据VID和PID定位即插即用设备实体  
  338.         /// </summary>  
  339.         /// <param name="VendorID">供应商标识,MinValue忽视</param>  
  340.         /// <param name="ProductID">产品编号,MinValue忽视</param>  
  341.         /// <returns>设备列表</returns>  
  342.         public static PnPEntityInfo[] WhoPnPEntity(UInt16 VendorID, UInt16 ProductID)  
  343.         {  
  344.             return WhoPnPEntity(VendorID, ProductID, Guid.Empty);  
  345.         }  
  346.   
  347.         /// <summary>  
  348.         /// 根据设备安装类GUID定位即插即用设备实体  
  349.         /// </summary>  
  350.         /// <param name="ClassGuid">设备安装类Guid,Empty忽视</param>  
  351.         /// <returns>设备列表</returns>  
  352.         public static PnPEntityInfo[] WhoPnPEntity(Guid ClassGuid)  
  353.         {  
  354.             return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, ClassGuid);  
  355.         }  
  356.   
  357.         /// <summary>  
  358.         /// 根据设备ID定位设备  
  359.         /// </summary>  
  360.         /// <param name="PNPDeviceID">设备ID,可以是不完整信息</param>  
  361.         /// <returns>设备列表</returns>  
  362.         /// <remarks>  
  363.         /// 注意:对于下划线,需要写成“[_]”,否则视为任意字符  
  364.         /// </remarks>  
  365.         public static PnPEntityInfo[] WhoPnPEntity(String PNPDeviceID)  
  366.         {  
  367.             List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();  
  368.   
  369.             // 枚举即插即用设备实体  
  370.             String QueryString;  
  371.             if (String.IsNullOrEmpty(PNPDeviceID))  
  372.             {  
  373.                 QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%VID[_]____&PID[_]____%'";  
  374.             }  
  375.             else  
  376.             {   // LIKE子句中有反斜杠字符将会引发WQL查询异常  
  377.                 QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%" + PNPDeviceID.Replace('\\', '_') + "%'";  
  378.             }  
  379.   
  380.             ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();  
  381.             if (PnPEntityCollection != null)  
  382.             {  
  383.                 foreach (ManagementObject Entity in PnPEntityCollection)  
  384.                 {  
  385.                     String thePNPDeviceID = Entity["PNPDeviceID"as String;  
  386.                     Match match = Regex.Match(thePNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");  
  387.                     if (match.Success)  
  388.                     {  
  389.                         PnPEntityInfo Element;  
  390.   
  391.                         Element.PNPDeviceID = thePNPDeviceID;                   // 设备ID  
  392.                         Element.Name = Entity["Name"as String;                // 设备名称  
  393.                         Element.Description = Entity["Description"as String;  // 设备描述  
  394.                         Element.Service = Entity["Service"as String;          // 服务  
  395.                         Element.Status = Entity["Status"as String;            // 设备状态  
  396.                         Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识  
  397.                         Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号  
  398.                         Element.ClassGuid = new Guid(Entity["ClassGuid"as String);            // 设备安装类GUID  
  399.   
  400.                         PnPEntities.Add(Element);  
  401.                     }  
  402.                 }  
  403.             }  
  404.   
  405.             if (PnPEntities.Count == 0) return nullelse return PnPEntities.ToArray();  
  406.         }  
  407.   
  408.         /// <summary>  
  409.         /// 根据服务定位设备  
  410.         /// </summary>  
  411.         /// <param name="ServiceCollection">要查询的服务集合,null忽视</param>  
  412.         /// <returns>设备列表</returns>  
  413.         /// <remarks>  
  414.         /// 跟服务相关的类:  
  415.         ///     Win32_SystemDriverPNPEntity  
  416.         ///     Win32_SystemDriver  
  417.         /// </remarks>  
  418.         public static PnPEntityInfo[] WhoPnPEntity(String[] ServiceCollection)  
  419.         {  
  420.             if (ServiceCollection == null || ServiceCollection.Length == 0)  
  421.                 return WhoPnPEntity(UInt16.MinValue, UInt16.MinValue, Guid.Empty);  
  422.   
  423.             List<PnPEntityInfo> PnPEntities = new List<PnPEntityInfo>();  
  424.   
  425.             // 枚举即插即用设备实体  
  426.             String QueryString = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID LIKE '%VID[_]____&PID[_]____%'";  
  427.             ManagementObjectCollection PnPEntityCollection = new ManagementObjectSearcher(QueryString).Get();  
  428.             if (PnPEntityCollection != null)  
  429.             {  
  430.                 foreach (ManagementObject Entity in PnPEntityCollection)  
  431.                 {  
  432.                     String PNPDeviceID = Entity["PNPDeviceID"as String;  
  433.                     Match match = Regex.Match(PNPDeviceID, "VID_[0-9|A-F]{4}&PID_[0-9|A-F]{4}");  
  434.                     if (match.Success)  
  435.                     {  
  436.                         String theService = Entity["Service"as String;            // 服务  
  437.                         if (String.IsNullOrEmpty(theService)) continue;  
  438.   
  439.                         foreach (String Service in ServiceCollection)  
  440.                         {   // 注意:忽视大小写  
  441.                             if (String.Compare(theService, Service, true) != 0) continue;  
  442.   
  443.                             PnPEntityInfo Element;  
  444.   
  445.                             Element.PNPDeviceID = PNPDeviceID;                      // 设备ID  
  446.                             Element.Name = Entity["Name"as String;                // 设备名称  
  447.                             Element.Description = Entity["Description"as String;  // 设备描述  
  448.                             Element.Service = theService;                           // 服务  
  449.                             Element.Status = Entity["Status"as String;            // 设备状态  
  450.                             Element.VendorID = Convert.ToUInt16(match.Value.Substring(4, 4), 16);   // 供应商标识  
  451.                             Element.ProductID = Convert.ToUInt16(match.Value.Substring(13, 4), 16); // 产品编号  
  452.                             Element.ClassGuid = new Guid(Entity["ClassGuid"as String);            // 设备安装类GUID  
  453.   
  454.                             PnPEntities.Add(Element);  
  455.                             break;  
  456.                         }  
  457.                     }  
  458.                 }  
  459.             }  
  460.   
  461.             if (PnPEntities.Count == 0) return nullelse return PnPEntities.ToArray();  
  462.         }  
  463.         #endregion          
  464.     }  
  465. }  


  


0 0