I'm running into an odd issue retrieving printer port addresses. When I get all the entries in Win32_TCPIPPrinterPort, the HostAddress field (which should have the IP address) is usually blank/null, only the port name has a value. To make it a bit stranger, if a particular port is not in use by any printer, THEN the HostAddress will have the the proper value.
The C# code is simple, and results in something like this; IP_192.168.1.100, printerportxyz,
richTextBox1.Clear();
ManagementObjectSearcher portSearcher = new ManagementObjectSearcher("root\\CIMV2",
"SELECT * FROM Win32_TCPIPPrinterPort");
foreach (ManagementObject port in portSearcher.Get())
{
richTextBox1.AppendText(
String.Format("Name: {0} HostAddress: {1}",
port["Name"],
port["HostAddress"])
);
}
I also tried the same thing in WSH/VBS, and saw the same behavior.