WMI(Windows??Management Instrumentation ) 非常强大,它可以以数据库的形式查询你的电脑的软件和硬件,在它的数据库里面,时刻保存着最新的软件信息和硬件信息,因此你可以用WMI来检测CUP 主频、温度,读取WINDOWS的进程......... 1. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 2. 3. Dialogs, StdCtrls, ExtCtrls,ActiveX, ComObj; 4. 5. 6. 7. procedure TForm1.Button2Click(Sender: TObject); 8. 9. var 10. 11. Locator: OleVariant; 12. 13. WMI: OleVariant; 14. 15. RET: OleVariant; 16. 17. Enum: IEnumVariant; 18. 19. Tmp: OleVariant; 20. 21. Value: Cardinal; 22. 23. begin; 24. 25. Locator := CreateOleObject('WbemScripting.SWbemLocator'); 26. 27. WMI := Locator.ConnectServer('.', '', '', ''); 28. 29. Ret := WMI.ExecQuery('SELECT * FROM Win32_USBHub');//这里Win32_USBHub为检测项,详见下表 30. 31. 32. 33. Enum:= IUnknown(RET._NewEnum) as IEnumVariant; 34. 35. while (Enum.Next(1, Tmp, Value) = S_OK) do 36. 37. begin 38. 39. if Tmp.Name='USB Mass Storage Device' then 40. 41. ShowMessage('这个u盘的硬件特征码是'+Tmp.PNPDeviceID);//Tmp为检测到返回的数据集合,其中PNPDeviceID为集合中的对象,包含了PID和VID码 42. 43. end; 44. 45. 46. 47. end; 48. 49. 50. 51. Win32_USBHub只是冰山一角,常用的还有以下 52. 53. 54. 55. "Win32_1394Controller" , 56. 57. "Win32_BaseBoard" , 58. 59. "Win32_Battery" , 60. 61. "Win32_BIOS" , 62. 63. "Win32_Bus" , 64. 65. "Win32_CacheMemory" , 66. 67. "Win32_CDROMDrive" , 68. 69. "Win32_CurrentProbe" , 70. 71. "Win32_DesktopMonitor" , 72. 73. "Win32_DeviceMemoryAddress" , 74. 75. "Win32_DiskDrive" , 76. 77. "Win32_DisplayConfiguration" , 78. 79. "Win32_DisplayControllerConfiguration", 80. 81. "Win32_DMAChannel" , 82. 83. "Win32_Fan" , 84. 85. "Win32_FloppyController" , 86. 87. "Win32_FloppyDrive" , 88. 89. "Win32_HeatPipe" , 90. 91. "Win32_IDEController" , 92. 93. "Win32_InfraredDevice" , 94. 95. "Win32_IRQResource" , 96. 97. "Win32_Keyboard" , 98. 99. "Win32_MemoryArray" , 100. 101. "Win32_MemoryDevice" , 102. 103. "Win32_MotherboardDevice" , 104. 105. "Win32_NetworkAdapter" , 106. 107. "Win32_NetworkAdapterConfiguration" , 108. 109. "Win32_OnBoardDevice" , 110. 111. "Win32_ParallelPort" , 112. 113. "Win32_PCMCIAController" , 114. 115. "Win32_PhysicalMemory" , 116. 117. "Win32_PhysicalMemoryArray" , 118. 119. "Win32_PnPEntity" , 120. 121. "Win32_PointingDevice" , 122. 123. "Win32_PortableBattery" , 124. 125. "Win32_PortConnector" , 126. 127. "Win32_PortResource" , 128. 129. "Win32_POTSModem" , 130. 131. "Win32_PowerManagementEvent" , 132. 133. "Win32_Printer" , 134. 135. "Win32_PrinterConfiguration" , 136. 137. "Win32_PrintJob" , 138. 139. "Win32_Processor" , 140. 141. "Win32_Refrigeration" , 142. 143. "Win32_SerialPort" , 144. 145. "Win32_SerialPortConfiguration" , 146. 147. "Win32_SMBIOSMemory" , 148. 149. "Win32_SoundDevice" , 150. 151. "Win32_SystemEnclosure" , 152. 153. "Win32_SystemMemoryResource" , 154. 155. "Win32_SystemSlot" , 156. 157. "Win32_TapeDrive" , 158. 159. "Win32_TemperatureProbe" , 160. 161. "Win32_UninterruptiblePowerSupply" , 162. 163. "Win32_USBController" , 164. 165. "Win32_VideoConfiguration" , 166. 167. "Win32_VideoController" , 168. 169. "Win32_VoltageProbe"
所有设备都在设备分类的Usb分支下,你可以遍历查找,也可以到注册表中找 特定设备的vidpid是设备指定的,看一下技术文档即可