By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,238 Members | 1,485 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,238 IT Pros & Developers. It's quick & easy.

PRINTER INFORMATION

P: n/a
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

Nov 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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
-----------------------------------------

"Morten Fagermoen" wrote:
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

Nov 18 '06 #2

P: n/a
Hi, again!

This worked fine.

Thank you very much, Ken!!

Morten
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.comwrote in message
news:CE**********************************@microsof t.com...
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
-----------------------------------------

"Morten Fagermoen" wrote:
>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

Nov 18 '06 #3

P: n/a
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)

"Morten Fagermoen" <mo****@fagermoen.comwrote in message
news:et**************@TK2MSFTNGP02.phx.gbl...
Hi, again!

This worked fine.

Thank you very much, Ken!!

Morten
"Ken Tucker [MVP]" <Ke**********@discussions.microsoft.comwrote in
message news:CE**********************************@microsof t.com...
>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
-----------------------------------------

"Morten Fagermoen" wrote:
>>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

Nov 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.