WMI查询不返回任何值 [英] WMI query not returning any values
问题描述
您好,
我正在尝试查询WMI以获取串行端口连接(COM端口)。我可以看到设备管理器上的端口,但在尝试通过WMI(Win32_SerialPort)查询它们时,没有任何显示。我可以通过HyperTerminal连接到其中一个端口(COM7)。它是我尝试使用C#连接的GSM / GPRS调制解调器。
调制解调器的设备管理器中的描述是HSPADatacard NMEA设备(COM7)。 br />
尝试在Win10机器上执行此操作。
非常感谢任何帮助。
我尝试过:
使用管理员权限运行cmd,'模式'当插入调制解调器时,命令确实反映了额外的COM端口。
使用WMICodeCreator生成VBscript来报告端口也没有产生任何结果。< br $>
脚本生成:
Hi there,
I'm trying to query the WMI for serial port connections (COM ports). I can see the ports on the Device Manager but when trying to query them through WMI (Win32_SerialPort), nothing shows up. I am able to connect to one of the ports (COM7) via the HyperTerminal. It is a GSM/GPRS modem that I am attempting to connect to using C#.
The description in Device Manager for the modem is HSPADatacard NMEA Device (COM7).
Attempting to do this on a Win10 machine.
Any help is much appreciated.
What I have tried:
Running cmd with admin rights, the 'mode' command does reflect the additional COM ports when the modem is plugged in.
Using a WMICodeCreator to generate a VBscript to report on the ports did not yield any results either.
Script generated:
strComputer = "."
<pre>Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_SerialPort",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_SerialPort instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DeviceID: " & objItem.DeviceID
Wscript.Echo "Name: " & objItem.Name
Next
推荐答案
Win32 \_SerialPort类| Microsoft Docs [ ^ ]仅列出物理串行端口,而不是设备驱动程序提供的虚拟串行端口。
一种解决方案是使用MSSerial_PortName $ \root \ WMI 命名空间中的c $ c>类。另请参阅使用WMI查询的SerialPorts列表与devicemanager不同? - 堆栈溢出 [ ^ ]。
The Win32\_SerialPort class | Microsoft Docs[^] lists only physical serial ports and not virtual ones provided by device drivers.
One solution is to use theMSSerial_PortName
class in the \root\WMI namespace. See also List of SerialPorts queried using WMI differs from devicemanager? - Stack Overflow[^].
@Jochen Arndt,尝试更改查询以使用MSSerial_PortName,我得到的只是查询中的错误,没有返回任何结果。
经过一番阅读后,以下查询确实有效:
@Jochen Arndt, Tried changing the query to use MSSerial_PortName and all I got was an error in the query with no results returned.
After some reading the following query did work:
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_PnPEntity WHERE Name LIKE '%COM%' AND PNPClass = 'Ports'",,48)
For Each objItem in colItems
Wscript.Echo "-----------------------------------"
Wscript.Echo "Win32_PnPEntity instance"
Wscript.Echo "-----------------------------------"
Wscript.Echo "Caption: " & objItem.Caption
Wscript.Echo "Description: " & objItem.Description
Wscript.Echo "DeviceID: " & objItem.DeviceID
If isNull(objItem.HardwareID) Then
Wscript.Echo "HardwareID: "
Else
Wscript.Echo "HardwareID: " & Join(objItem.HardwareID, ",")
End If
Wscript.Echo "Manufacturer: " & objItem.Manufacturer
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "PNPClass: " & objItem.PNPClass
Wscript.Echo "PNPDeviceID: " & objItem.PNPDeviceID
Next
生成输出:
That generated the output of :
----------------------------- ------
Win32_PnPEntity实例
-------------------------- ---------
说明:HSPADataCard NMEA设备(COM7)
描述:HSPADataCard NMEA设备
DeviceID:USB \\ \\ _VID_19D2& PID_0082& MI_01 \6& 1C9A94D5& 0& 0001
硬件ID:USB \VID_19D2& PID_0082& REV_0000& MI_01,USB \VID_19D2& PID_0082& MI_01
制造商:HSPADataCard
名称:HSPADataCard NMEA设备(COM7)
PNPClass:端口
PNPDeviceID:USB \VID_19D2& PID_0082& MI_01 \ 6& 1C9A94D5& 0& 0001
-----------------------------------
Win32_PnPEntity instance
-----------------------------------
Caption: HSPADataCard NMEA Device (COM7)
Description: HSPADataCard NMEA Device
DeviceID: USB\VID_19D2&PID_0082&MI_01\6&1C9A94D5&0&0001
HardwareID: USB\VID_19D2&PID_0082&REV_0000&MI_01,USB\VID_19D2&PID_0082&MI_01
Manufacturer: HSPADataCard
Name: HSPADataCard NMEA Device (COM7)
PNPClass: Ports
PNPDeviceID: USB\VID_19D2&PID_0082&MI_01\6&1C9A94D5&0&0001
下一步将是查询和/或设置相关端口的参数(如波特率,奇偶校验等)
The next step will be to query and/or set the relevant port's parameters (like Baud rate, parity etc)
这篇关于WMI查询不返回任何值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!