Hi Experts,
How to get the list of network printers over the current network /domain using C# and not from the local machine ?
Loading
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
VulpesRank #55 · 29.2K reputationPosted Jun 22, 2011, 12:22 AM EDT
Here's some C# code to try:
Posted Jun 22, 2011, 12:47 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jun 22, 2011, 4:32 AM EDT
To get all network printers in the current domain, I think you'll need to call the API function EnumPrinters (http://msdn.microsoft.com/en-us/library/dd162692(VS.85).aspx) and pass it the PRINTER_ENUM_NETWORK flag. The printer information (including the name) will then be returned in an array of PRINTER_INFO_1 structs.
Try the following:
Posted Jun 22, 2011, 5:10 AM EDT
Thanks for your response. I was also looking the same link.
If I pass the enum value as "PRINTER_ENUM_NETWORK" it is not returning any printer details but if I change the enum value to
PRINTER_ENUM_LOCAL then it is returning all my local system printers.
For enumerating the N/W printer do I need domain Administrator ? Please suggest me.
I got an one more sample code to get all the n/w printers by using the Active Directory.
Imports System
Imports System.DirectoryServices
Public Class Foo
Public Shared Sub Main(args() As String)
Dim entry As New DirectoryEntry("LDAP://DC=redmond, DC=corp, DC=microsoft, DC=com")
Dim searcher As New DirectorySearcher(entry)
searcher.Filter = "(objectCategory=printQueue)"
Dim result As SearchResult
For Each result In searcher.FindAll()
Console.WriteLine(result.GetDirectoryEntry().Path)
Next
End Sub
End Class
Source Link : http://forums.asp.net/t/443425.aspx/1
VulpesRank #55 · 29.2K reputationPosted Jun 22, 2011, 6:05 AM EDT
Do you get any printers returned if you use PRINTER_ENUM_REMOTE with the Name argument set to "Print Provider!Domain" ?
If you can use Active Directory and the sample code is working, I'd be inclined to go with that.
Sam HobbsRank #108 · 20.5K reputationPosted Jun 22, 2011, 7:23 AM EDT