PRINTER INFORMATION

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Morten Fagermoen

    #1

    PRINTER INFORMATION

    Hi!

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

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


    Public Sub EnumerateConnec tedPrinters(ByV al objECP As
    System.Collecti ons.Generic.Lis t(Of String))
    Dim strPrinter As String
    Try
    objECP.Clear()
    For Each strPrinter In PrinterSettings .InstalledPrint ers
    'How can I find LOCATION and DESCRIPTION on a connected printer
    If CBool(InStr(1, strPrinter, "\\",
    Microsoft.Visua lBasic.CompareM ethod.Text)) Then
    objECP.Add(Spli t(strPrinter, "\")(3) & "," &
    Split(strPrinte r, "\")(2) & ",,")
    Else
    objECP.Add(strP rinter & ",,,")
    End If
    Next strPrinter
    Catch ex As Exception
    'If bDebug Then Console.WriteLi ne("Error - Failed when disconnecting
    network printers.")
    logfile.WriteLi ne("Error - Failed to enumerate connected printers.")
    logfile.Flush()
    Finally
    strPrinter = Nothing
    End Try
    End Sub



    Regards

    Morten Fagermoen

  • Ken Tucker [MVP]

    #2
    RE: PRINTER INFORMATION

    Hi,

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

    Dim moReturn As Management.Mana gementObjectCol lection
    Dim moSearch As Management.Mana gementObjectSea rcher
    Dim mo As Management.Mana gementObject

    moSearch = New Management.Mana gementObjectSea rcher("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 "Descriptio n" information from the printers
    I have connected?
    >
    >
    Public Sub EnumerateConnec tedPrinters(ByV al objECP As
    System.Collecti ons.Generic.Lis t(Of String))
    Dim strPrinter As String
    Try
    objECP.Clear()
    For Each strPrinter In PrinterSettings .InstalledPrint ers
    'How can I find LOCATION and DESCRIPTION on a connected printer
    If CBool(InStr(1, strPrinter, "\\",
    Microsoft.Visua lBasic.CompareM ethod.Text)) Then
    objECP.Add(Spli t(strPrinter, "\")(3) & "," &
    Split(strPrinte r, "\")(2) & ",,")
    Else
    objECP.Add(strP rinter & ",,,")
    End If
    Next strPrinter
    Catch ex As Exception
    'If bDebug Then Console.WriteLi ne("Error - Failed when disconnecting
    network printers.")
    logfile.WriteLi ne("Error - Failed to enumerate connected printers.")
    logfile.Flush()
    Finally
    strPrinter = Nothing
    End Try
    End Sub
    >
    >
    >
    Regards
    >
    Morten Fagermoen
    >
    >

    Comment

    • Morten Fagermoen

      #3
      Re: PRINTER INFORMATION

      Hi, again!

      This worked fine.

      Thank you very much, Ken!!

      Morten


      "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.comwrote in message
      news:CE90F881-7674-441A-96B1-4E38D6C181C4@mi crosoft.com...
      Hi,
      >
      You need to use the wmi to get more info. Add a reference to
      system.manageme nt
      >
      Dim moReturn As Management.Mana gementObjectCol lection
      Dim moSearch As Management.Mana gementObjectSea rcher
      Dim mo As Management.Mana gementObject
      >
      moSearch = New Management.Mana gementObjectSea rcher("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 "Descriptio n" information from the
      >printers
      >I have connected?
      >>
      >>
      >Public Sub EnumerateConnec tedPrinters(ByV al objECP As
      >System.Collect ions.Generic.Li st(Of String))
      > Dim strPrinter As String
      > Try
      > objECP.Clear()
      > For Each strPrinter In PrinterSettings .InstalledPrint ers
      > 'How can I find LOCATION and DESCRIPTION on a connected
      >printer
      > If CBool(InStr(1, strPrinter, "\\",
      >Microsoft.Visu alBasic.Compare Method.Text)) Then
      > objECP.Add(Spli t(strPrinter, "\")(3) & "," &
      >Split(strPrint er, "\")(2) & ",,")
      > Else
      > objECP.Add(strP rinter & ",,,")
      > End If
      > Next strPrinter
      > Catch ex As Exception
      > 'If bDebug Then Console.WriteLi ne("Error - Failed when
      >disconnectin g
      >network printers.")
      > logfile.WriteLi ne("Error - Failed to enumerate connected
      >printers.")
      > logfile.Flush()
      > Finally
      > strPrinter = Nothing
      > End Try
      >End Sub
      >>
      >>
      >>
      >Regards
      >>
      >Morten Fagermoen
      >>
      >>

      Comment

      • Duncan Jones

        #4
        Re: PRINTER INFORMATION

        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" <morten@fagermo en.comwrote in message
        news:etdoqv0CHH A.5068@TK2MSFTN GP02.phx.gbl...
        Hi, again!
        >
        This worked fine.
        >
        Thank you very much, Ken!!
        >
        Morten
        >
        >
        "Ken Tucker [MVP]" <KenTuckerMVP@d iscussions.micr osoft.comwrote in
        message news:CE90F881-7674-441A-96B1-4E38D6C181C4@mi crosoft.com...
        >Hi,
        >>
        > You need to use the wmi to get more info. Add a reference to
        >system.managem ent
        >>
        > Dim moReturn As Management.Mana gementObjectCol lection
        > Dim moSearch As Management.Mana gementObjectSea rcher
        > Dim mo As Management.Mana gementObject
        >>
        > moSearch = New Management.Mana gementObjectSea rcher("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 "Descriptio n" information from the
        >>printers
        >>I have connected?
        >>>
        >>>
        >>Public Sub EnumerateConnec tedPrinters(ByV al objECP As
        >>System.Collec tions.Generic.L ist(Of String))
        >> Dim strPrinter As String
        >> Try
        >> objECP.Clear()
        >> For Each strPrinter In PrinterSettings .InstalledPrint ers
        >> 'How can I find LOCATION and DESCRIPTION on a connected
        >>printer
        >> If CBool(InStr(1, strPrinter, "\\",
        >>Microsoft.Vis ualBasic.Compar eMethod.Text)) Then
        >> objECP.Add(Spli t(strPrinter, "\")(3) & "," &
        >>Split(strPrin ter, "\")(2) & ",,")
        >> Else
        >> objECP.Add(strP rinter & ",,,")
        >> End If
        >> Next strPrinter
        >> Catch ex As Exception
        >> 'If bDebug Then Console.WriteLi ne("Error - Failed when
        >>disconnecti ng
        >>network printers.")
        >> logfile.WriteLi ne("Error - Failed to enumerate connected
        >>printers.")
        >> logfile.Flush()
        >> Finally
        >> strPrinter = Nothing
        >> End Try
        >>End Sub
        >>>
        >>>
        >>>
        >>Regards
        >>>
        >>Morten Fagermoen
        >>>
        >>>
        >

        Comment

        Working...