Let me cut & paste some code I have:
First, lets say you have a printer who's IP address is {string}:
"192.168.33.99"
And then, lets say you have a Queue on your printer, like:
"XRX_Swop"
Then this is the code I would use:
VB Code:
'In a sub somewhere:
MyLPStr = "lpr -S " & "192.168.33.99" & " -P " & "XRX_Swop" & " "
SyncShellCmd MyLPStr & "-J" & Chr$(34) & "p003456-save" & Chr$(34) & " " & Chr$(34) & "C:\p003456-duplex-save.pdf" & Chr$(34), 0
'Then, you have the function SyncShellCmd somewhere in your
'forms code:
Public Function SyncShellCmd(CmdStr As String, ByVal ApplicationFocus As Long) As Boolean
'Run the application by the CmdStr, and exit when the program terminated, Application focus specific
'the focus of the application. e.g vbNormalFocus
Dim lPid As Long 'The task ID of the started program
Dim lHnd As Long ' handle to object to wait for
Dim lRet As Long 'Return value of WaitForSingleObject()
SyncShellCmd = False
If CmdStr = "" Then Exit Function
lPid = Shell(CmdStr, ApplicationFocus)
If lPid <> 0 Then
'Get a handle to the shelled process.
lHnd = OpenProcess(&H100000, 0, lPid)
'If successful, wait for the application to end and close the handle.
If lHnd <> 0 Then
lRet = WaitForSingleObject(lHnd, &HFFFF) 'no time out
CloseHandle (lHnd)
SyncShellCmd = True
End If
End If
End Function
'Either put these three in a Bas, declared as public,
'or at the top of your forms code module:
Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
-Hope this helps
-Lou
BTW, the point of all this is you are essentially shelling to the LPR.exe, if you happen to have it on your system.