Click to See Complete Forum and Search --> : Print to network printer


aswinasokan
May 18th, 2001, 07:08 AM
How can I print to a printer installed on the network, but not added to my computer.
I know the path of the printer (e.g //Computer/PrinterName). Is this information sufficient to send data to be printed on the network printer.?
Also what functions should I being looking into ??

Any help on this will be of great help to me

Regards
Aswin Asokan

Iouri
May 18th, 2001, 07:12 AM
VB always prints to the default printer. If network printer is a default one then
Printer.Print
will send the printout to this printer. Check your Control Panel->Printers and you will see which printer is default.

If you need code how to list all the printers installed on your computer or how to change the default printer, let me know

Iouri Boutchkine
iouri@hotsheet.com

aswinasokan
May 21st, 2001, 07:58 AM
The printer may/maynot be installed on my computer. Still, which just the knowledge of its location on the network I need to send data to be printed. This has to be done programatically.

Regards
Aswin Asokan

Cimperiali
May 21st, 2001, 08:08 AM
May be this may help:
(this gets also network printers...but I am afraid they should be installed locally).
' Get information about all of the local printers using structure 1. Note how
' the elements of the array are loaded into an array of data structures manually. Also
' note how the following special declares must be used to allow numeric string pointers
' to be used in place of strings:
Private Declare Function lstrcpy Lib "kernel32.dll" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
Private Declare Function lstrlen Lib "kernel32.dll" Alias "lstrlenA" (ByVal lpString As Long) As Long
Private Declare Function EnumPrinters Lib "winspool.drv" Alias "EnumPrintersA" (ByVal flags As Long, ByVal name As String, ByVal Level As Long, pPrinterEnum As Long, ByVal cdBuf As Long, pcbNeeded As Long, pcReturned As Long) As Long
Const PRINTER_ENUM_LOCAL = &H2
Private Type PRINTER_INFO_1
flags As Long
pDescription As String
pName As String
pComment As String
End Type
Private Sub Form_Load()
'KPD-Team 1999
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Dim longbuffer() As Long ' resizable array receives information from the function
Dim printinfo() As PRINTER_INFO_1 ' values inside longbuffer() will be put into here
Dim numbytes As Long ' size in bytes of longbuffer()
Dim numneeded As Long ' receives number of bytes necessary if longbuffer() is too small
Dim numprinters As Long ' receives number of printers found
Dim c As Integer, retval As Long ' counter variable & return value
Me.AutoRedraw = True 'Set current graphic mode to persistent
' Get information about the local printers
numbytes = 3076 ' should be sufficiently big, but it may not be
ReDim longbuffer(0 To numbytes / 4) As Long ' resize array -- note how 1 Long = 4 bytes
retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
If retval = 0 Then ' try enlarging longbuffer() to receive all necessary information
numbytes = numneeded
ReDim longbuffer(0 To numbytes / 4) As Long ' make it large enough
retval = EnumPrinters(PRINTER_ENUM_LOCAL, "", 1, longbuffer(0), numbytes, numneeded, numprinters)
If retval = 0 Then ' failed again!
Debug.Print "Could not successfully enumerate the printes."
End ' abort program
End If
End If
' Convert longbuffer() data into printinfo()
If numprinters <> 0 Then ReDim printinfo(0 To numprinters - 1) As PRINTER_INFO_1 ' room for each printer
For c = 0 To numprinters - 1 ' loop, putting each set of information into each element
' longbuffer(4 * c) = .flags, longbuffer(4 * c + 1) = .pDescription, etc.
' For each string, the string is first buffered to provide enough room, and then the string is copied.
printinfo(c).flags = longbuffer(4 * c)
printinfo(c).pDescription = Space(lstrlen(longbuffer(4 * c + 1)))
retval = lstrcpy(printinfo(c).pDescription, longbuffer(4 * c + 1))
printinfo(c).pName = Space(lstrlen(longbuffer(4 * c + 2)))
retval = lstrcpy(printinfo(c).pName, longbuffer(4 * c + 2))
printinfo(c).pComment = Space(lstrlen(longbuffer(4 * c + 3)))
retval = lstrcpy(printinfo(c).pComment, longbuffer(4 * c + 3))
Next c
' Display name of each printer
For c = 0 To numprinters - 1
Me.Print "Name of printer"; c + 1; " is: "; printinfo(c).pName
Next c
End Sub




Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.

Dark Sean
May 21st, 2001, 08:10 AM
I needed to do the same thing, and the best way I found to do it was with the FileSystemObject. If you are not familiar with it, you will have to add a reference to Microsoft Scripting Runtime and then here is the simple code.


Dim FSO as new FileSystemObject
FSO.CopyFile YourFile, "\\Computer\Printer"
set FSO = nothing




Hope that helps...