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:
JavaScript
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 The Win32\_SerialPort class | Microsoft Docs [ ^ ] lists only physical serial ports and not virtual ones provided by device drivers.
One solution is to use the MSSerial_PortName class in the \root\WMI namespace. See also List of SerialPorts queried using WMI differs from devicemanager? - Stack Overflow [ ^ ]. @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:
JavaScript
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: " 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 That generated the output of :
Quote:
-----------------------------------
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)
  • Read the question carefully.
  • Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  • If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  • Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question. Let's work to help developers, not make them feel stupid.
  •