Reputation: 4789
Is it possible to get network printer path using the following convention in C#
computername\printername
PrinterSettings.Installed printer gives out the printer name but not the path information.
Thanks in advance
Upvotes: 0
Views: 2695
Reputation: 945
A quick and dirty way to get this information is to use the IWshRuntimeLibrary library (wshom.ocx).
WshNetwork network = new WshNetwork();
var printers = network.EnumPrinterConnections();
for (int i = 0; i < printers.Count(); i += 2)
{
Console.WriteLine(printers.Item(i) + " \t" + printers.Item(i+1));
}
...But a more forward looking approach would be to use the information contained within Winspool's PRINTER_INFO_2 structure which is returned from the GetPrinter method.
http://www.pinvoke.net/default.aspx/Structures/PRINTER_INFO_2.html
http://msdn.microsoft.com/en-us/library/windows/desktop/dd162845%28v=vs.85%29.aspx
http://www.pinvoke.net/default.aspx/winspool.getprinter
http://msdn.microsoft.com/en-us/library/windows/desktop/dd144911%28v=vs.85%29.aspx
Upvotes: 1
Reputation: 1242
This works for printer mapping. you need to make sure to add IWshRuntimeLibrary as a reference:
using IWshRuntimeLibrary;
private void MappPrinter()
{
WshNetwork oNetwork = new WshNetwork();
oNetwork.AddWindowsPrinterConnection("\\\\computername\\printername", "HPLJ6000","\\\\computername\\printername");
}
Upvotes: 1