I am unable to detect my Network Printer's IP Address / Hostname. Is there something wrong in my code below?
ConnectionOptions myConnectionOptions = new ConnectionOptions();
myConnectionOptions.Impersonation = ImpersonationLevel.Impersonate;
myConnectionOptions.Authentication = System.Management.AuthenticationLevel.Packet;
string myServerName = ".";
ManagementScope myManagementScope = new ManagementScope(@"\root\cimv2");
myManagementScope.Connect();
SelectQuery selectQuery = new SelectQuery();
selectQuery.QueryString = String.Format("SELECT * FROM Win32_TCPIPPrinterPort WHERE Name = 'IP_10.25.1.221'");
if (myManagementScope.IsConnected == false) Console.WriteLine("Could not connect to WMI namespace");
ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(myManagementScope, selectQuery);
foreach (ManagementObject objMgmt in managementObjectSearcher.Get())
{
if (objMgmt["Caption"].ToString()== "")
{
...
}
}
}
catch (Exception err) { Console.WriteLine("Err:"+ err.Message); }
Hope you can advise me..