PRINTER INFORMATION

  • Thread starter Thread starter Morten Fagermoen
  • Start date Start date
M

Morten Fagermoen

Hi!

I use the code below to find the printers connected to the local computer.

How can I get the "Location" and "Description" information from the printers
I have connected?


Public Sub EnumerateConnectedPrinters(ByVal objECP As
System.Collections.Generic.List(Of String))
Dim strPrinter As String
Try
objECP.Clear()
For Each strPrinter In PrinterSettings.InstalledPrinters
'How can I find LOCATION and DESCRIPTION on a connected printer
If CBool(InStr(1, strPrinter, "\\",
Microsoft.VisualBasic.CompareMethod.Text)) Then
objECP.Add(Split(strPrinter, "\")(3) & "," &
Split(strPrinter, "\")(2) & ",,")
Else
objECP.Add(strPrinter & ",,,")
End If
Next strPrinter
Catch ex As Exception
'If bDebug Then Console.WriteLine("Error - Failed when disconnecting
network printers.")
logfile.WriteLine("Error - Failed to enumerate connected printers.")
logfile.Flush()
Finally
strPrinter = Nothing
End Try
End Sub



Regards

Morten Fagermoen
 
Hi,

You need to use the wmi to get more info. Add a reference to
system.management

Dim moReturn As Management.ManagementObjectCollection
Dim moSearch As Management.ManagementObjectSearcher
Dim mo As Management.ManagementObject

moSearch = New Management.ManagementObjectSearcher("Select * from
Win32_Printer")

moReturn = moSearch.Get

For Each mo In moReturn
Dim strOut As String
strOut = String.Format("Name {0} - {1} - {2}", mo("Name"),
mo("location"), mo("description"))
Trace.WriteLine(strOut)
Next


Ken
 
You can also use the windows API.
e.g. GetPrinter , EnumPrinters etc.
There is a component wrapper called PrintQueueWatch.NET for this and other
printer API calls on my website and on the CodePlex site
(http://www.codeplex.com/PUMA)
 
Back
Top