Getting serial port information over WMI

F

Frank

Hello,

how to get information about all serial ports in the PC?

I use the following code, but i got only the data of the FIRST serial port.
All other serial port information are not available with this code sample:

ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select *
from WIN32_SerialPort");

foreach(ManagementObject Port in searcher.Get()) {

string a = (string) Port.GetPropertyValue("Name");

}

Does anybody knows how to get informations about ALL serial ports?

Thanks

Frank
 
J

Jochen Albert

Frank said:
Hello,

how to get information about all serial ports in the PC?

I use the following code, but i got only the data of the FIRST serial port.
All other serial port information are not available with this code sample:

ManagementObjectSearcher searcher = new ManagementObjectSearcher("Select *
from WIN32_SerialPort");

foreach(ManagementObject Port in searcher.Get()) {

string a = (string) Port.GetPropertyValue("Name");

}

Does anybody knows how to get informations about ALL serial ports?

Thanks

Frank

Sorry, i don't know how to do this over WMI.

You could use CreateFile("COM1", ....) (from kernel32.dll) to try each
possible port (if the returned file handle is -1 the port isn't there.)
 
F

Frank

Hello Jochen,

your soultion is not suitable for me because i cannot get information, if
the serial port was a native serial port, a USB serial port adapter or a
bluetooth serial port adapter for example. I need specially this
information.

Bye

Frank
 
J

Jochen Albert

I would like to know that, too. So, if you find a solution... :)
In the Registry theres only the drivers name asociated to a com port,
that may be a clue, but of course no solution.
 
G

Guest

Hi ,
I'm trying to connect to a Serial port using the Kernel32.dll but having
trouble connecting to the port.
Can you share a simple code as to how you communicate with a serial port. I
appreciate your help.
Thanks
-ZS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top