How could I get printer's network path (\\COMPUTER\PRINTERNAME) from default printer, when the default printer isn't local?
Thx in adv.
How could I get printer's network path (\\COMPUTER\PRINTERNAME) from default printer, when the default printer isn't local?
Thx in adv.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jan MontanoPosted Feb 21, 2008, 3:47 AM
I'm not sure if the EnumPrinters API will return uninstalled printers though.
SANDIPPosted Feb 21, 2008, 1:49 AM
Thanks for your reply.
The code I have used gives me only the printers that are added on my local machine. It means , if I want to show the printers using this code, then first it should be added on my local machine. The printers avaliable in my local network but not installed/ added on my machine are not shown by this code.
I am searching for something that could help me to show all the printers that are avaliable in my local network but not installed/ added on my machine.
Where can I get something to read regarding this?
Jan MontanoPosted Feb 20, 2008, 12:48 AM
When you click on Start->Printers and Faxes, this will list all your printers. This list should be the same as with the queryCollection.
SANDIPPosted Feb 19, 2008, 11:35 PM
Thanks for your reply.
I have used System.Management namespace and the query, but it gives the address path of the printers installed on local machine only, it do not display network printers information.
Here is the code I used to get information,
string
strQuery = "SELECT * FROM Win32_Printer";System.
Console.WriteLine("WMI Query: '{0}'", strQuery);System.
Console.WriteLine("==============================================");System.Management.
ObjectQuery oq = newSystem.Management.
ObjectQuery(strQuery);System.Management.
ManagementObjectSearcher query1 = newSystem.Management.
ManagementObjectSearcher(oq);System.Management.
ManagementObjectCollection queryCollection1 =query1.Get();
System.Management.
ManagementObject newDefault = null;Is there something that I am missing?
Jan MontanoPosted Feb 19, 2008, 10:19 PM
using System.Management;
static void GetDefaultPrinter()
{
string strQuery = "SELECT * FROM Win32_Printer";
ObjectQuery objectQuery = new ObjectQuery(strQuery);
ManagementObjectSearcher query = new ManagementObjectSearcher(objectQuery);
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject managementObject in queryCollection )
{
PropertyDataCollection propertyDataCollection = managementObject.Properties;
if ((bool)managementObject["Default"]) // DEFAULT PRINTER
{
Console.WriteLine(managementObject["Name"]);
Console.WriteLine(managementObject["Location"]);
}
}
}