Problem retrieving Hostaddress from Win32_TCPIPPrinterPort
Posted
by Anthony
on Stack Overflow
See other posts from Stack Overflow
or by Anthony
Published on 2009-04-07T17:46:28Z
Indexed on
2010/06/05
16:52 UTC
Read the original article
Hit count: 410
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.
© Stack Overflow or respective owner