我正在做一个通过lpt端口控制一些设备的项目。我使用inpout32.dll获取对端口的原始访问,现在尝试枚举所有可用的LPT端口并获取它们的I/O范围。
我现在可以查看设备管理器了,但是有没有更自动化的方法呢?
现在,我正在尝试使用WMI一些示例代码,它们应该可以工作,但它不能工作
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
Set parallelports = wmiService.ExecQuery("SELECT * FROM Win32_ParallelPort")
For Each port In parallelports
q = "SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID = '" & port.PNPDeviceID & "'"
Set pnpentities = wmiService.ExecQuery(q)
For Each pnpentity In pnpentities
wscript.echo pnpentity.PNPDeviceID
Next
Next在'For Each pnpentity In pnpentity‘行,我得到了错误。此外,我也不舒尔,如果找到相应的实体将帮助我。
PS。最后,我想出了如何枚举lpt i/o端口范围。
Set wmiService = GetObject("winmgmts:\\.\root\cimv2")
Set parallelports = wmiService.ExecQuery("SELECT * FROM Win32_ParallelPort")
For Each port In parallelports
Set port_resources = wmiService.ExecQuery("ASSOCIATORS OF {Win32_ParallelPort.DeviceID='" & port.DeviceID & "'} WHERE ResultClass = Win32_PortResource")
For Each port_resource In port_resources
wscript.echo port_resource.Caption
Next
Next发布于 2010-07-25 00:49:27
您会得到一个错误,因为PNPDeviceID包含反斜杠(\),而WQL查询中的反斜杠必须加倍。在将\插入到查询中之前,只需在port.PNPDeviceID中用\\替换它,您的脚本就会正常工作:
strPNPDeviceID = Replace(port.PNPDeviceID, "\", "\\")
Set pnpentities = wmiService.ExecQuery( _
"SELECT * FROM Win32_PnPEntity WHERE PNPDeviceID = '" & strPNPDeviceID & "'")你可能也会发现这个问题很有用:How to find available parallel ports and their I/O addresses using Delphi and WMI。
https://stackoverflow.com/questions/3325560
复制相似问题