Home All Groups Group Topic Archive Search About
Author
18 Nov 2006 3:26 PM
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

Author
18 Nov 2006 3:57 PM
Ken Tucker [MVP]
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
-----------------------------------------

Show quoteHide quote
"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
>
>
Author
18 Nov 2006 7:58 PM
Morten Fagermoen
Hi, again!

This worked fine.

Thank you very much, Ken!!

Morten


Show quoteHide quote
"Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in message
news:CE90F881-7674-441A-96B1-4E38D6C181C4@microsoft.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
>>
>>
Author
19 Nov 2006 8:22 PM
Duncan Jones
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)

Show quoteHide quote
"Morten Fagermoen" <mor***@fagermoen.com> wrote in message
news:etdoqv0CHHA.5068@TK2MSFTNGP02.phx.gbl...
> Hi, again!
>
> This worked fine.
>
> Thank you very much, Ken!!
>
> Morten
>
>
> "Ken Tucker [MVP]" <KenTucker***@discussions.microsoft.com> wrote in
> message news:CE90F881-7674-441A-96B1-4E38D6C181C4@microsoft.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
>>>
>>>
>