By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,157 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,157 IT Pros & Developers. It's quick & easy.

Getting serial port information over WMI

P: n/a
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
Feb 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Frank wrote:
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.)

Feb 21 '06 #2

P: n/a
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

"Jochen Albert" <me************@gmx.de> schrieb im Newsbeitrag
news:dt**********@news.cognex.com...
Frank wrote:
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.)

Feb 21 '06 #3

P: n/a
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.

Frank wrote:
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

"Jochen Albert" <me************@gmx.de> schrieb im Newsbeitrag
news:dt**********@news.cognex.com...
Frank wrote:
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.)


Feb 21 '06 #4

P: n/a
ZS
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

"Jochen Albert" wrote:
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.

Frank wrote:
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

"Jochen Albert" <me************@gmx.de> schrieb im Newsbeitrag
news:dt**********@news.cognex.com...
Frank wrote:
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.)


Feb 28 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.