Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Determine Printer Port

Determine Printer Port

Scheduled Pinned Locked Moved Visual Basic
csharptutorialquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    thebread
    wrote on last edited by
    #1

    hey all, Does anyone know, how to determine the port of a printer? I need this to know because my application allows a user to select a printer but all print jobs are send directly to the port (i.E. "copy print.txt LPT1"). I do not find any information abount this :( I'm using VB.NET 1.1 thx, bernd

    D 1 Reply Last reply
    0
    • T thebread

      hey all, Does anyone know, how to determine the port of a printer? I need this to know because my application allows a user to select a printer but all print jobs are send directly to the port (i.E. "copy print.txt LPT1"). I do not find any information abount this :( I'm using VB.NET 1.1 thx, bernd

      D Offline
      D Offline
      Duncan Edwards Jones
      wrote on last edited by
      #2

      The GetPrinter API can be used from VB.Net to get this info. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

      T 1 Reply Last reply
      0
      • D Duncan Edwards Jones

        The GetPrinter API can be used from VB.Net to get this info. '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

        T Offline
        T Offline
        thebread
        wrote on last edited by
        #3

        Thx very much !! after knowing what i am looking for i found this: <DllImport("winspool.drv", CharSet:=CharSet.Auto, SetLastError:=True)> _ Private Shared Function OpenPrinter( _ ByVal pPrinterName As String, ByRef hPrinter As IntPtr, _ ByVal pDefault As IntPtr) As Boolean End Function <DllImport("winspool.drv", CharSet:=CharSet.Auto, _ SetLastError:=True)> _ Private Shared Function ClosePrinter( _ ByVal hPrinter As IntPtr) As Boolean End Function <DllImport("winspool.drv", CharSet:=CharSet.Auto, _ SetLastError:=True)> _ Private Shared Function GetPrinter( _ ByVal hPrinter As IntPtr, ByVal dwLevel As Integer, _ ByVal pPrinter As IntPtr, ByVal cbBuf As Integer, _ ByRef pcbNeeded As Integer) As Boolean End Function Private Shared Function GetPrinterInfo(ByVal printerName As String) As PRINTER_INFO_2 Dim hPrinter As IntPtr If Not OpenPrinter(printerName, hPrinter, IntPtr.Zero) Then Throw New Win32Exception(Marshal.GetLastWin32Error()) End If Dim pPrinterInfo As IntPtr = IntPtr.Zero Try Dim needed As Integer GetPrinter(hPrinter, 2, IntPtr.Zero, 0, needed) If needed <= 0 Then Throw New Exception("Na Zeavas...") End If pPrinterInfo = Marshal.AllocHGlobal(needed) Dim temp As Integer If Not GetPrinter(hPrinter, 2, pPrinterInfo, needed, temp) Then Throw New Win32Exception(Marshal.GetLastWin32Error()) End If Dim printerInfo As PRINTER_INFO_2 = _ CType(Marshal.PtrToStructure( _ pPrinterInfo, GetType(PRINTER_INFO_2)), PRINTER_INFO_2) Return printerInfo Finally ClosePrinter(hPrinter) Marshal.FreeHGlobal(pPrinterInfo) End Try End Function <StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Auto)> _ Public Structure PRINTER_INFO_2 Public pServerName As String Public pPrinterName As String Public pShareName As String Public pPortName As String Public pDriverName As String Public pComment As String Public pLoca

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups