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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Jan MontanoRank #1,295 · 1.3K reputationPosted Feb 19, 2008, 5:19 PM EST
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"]);
}
}
}
SANDIP18 reputationPosted Feb 19, 2008, 6:35 PM EST
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 MontanoRank #1,295 · 1.3K reputationPosted Feb 19, 2008, 7:48 PM EST
When you click on Start->Printers and Faxes, this will list all your printers. This list should be the same as with the queryCollection.
SANDIP18 reputationPosted Feb 20, 2008, 8:49 PM EST
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 MontanoRank #1,295 · 1.3K reputationPosted Feb 20, 2008, 10:47 PM EST
I'm not sure if the EnumPrinters API will return uninstalled printers though.