Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
We have a requirement to get the printer IP Address configured in the default printer driver in Control Panel in our UWP app.

I was able to retrieve the "System.DeviceInterface.PrinterPortName" by fetching interface class GUID and passing this above property for retrieval.

But I couldn't get "System.Devices.IpAddress" similarly. Code pasted below for PortName.

I badly need the IP address as the port name is user's choice and could be modified to any name removing the IP address.

Kindly help sharing working code to retrieve the IP Address using above property or any other way in UWP app.

Below is Working Code for Port Name, Kindly help to fetch IP Address of the same port similarly.

What I have tried:

string aqsFilter = "System.Devices.InterfaceClassGuid:=\"{0ecef634-6ef0-472a-8085-5ad023ecbccd}\"";

string[] propertiesToRetrieve = new string[] { "System.DeviceInterface.PrinterPortName"};

DeviceInformationCollection deviceInfoCollection = await DeviceInformation.FindAllAsync(aqsFilter, propertiesToRetrieve);

foreach (DeviceInformation deviceInfo in deviceInfoCollection)
{
if (deviceInfo.IsDefault == true)
{
string strPortName = (string)deviceInfo.Properties["System.DeviceInterface.PrinterPortName"];

if (!string.IsNullOrEmpty(strPortName))
{
strPortName = await ParsePortName(strPortName);
if (!string.IsNullOrEmpty(strPortName))
{
_strIPAddress = strPortName;
}
}
break;
}
}
Posted
Comments
SiD1989 2-May-18 0:47am    
Anyone who's expertise in this area.. kindly provide me solution or any suggestions. This is very critical for me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900