hab das problem behoben!
die "waitforproceed" funktion sollte man halt mitnutzen. hast du wohl vergessen wolf. und die millisekunden zahl korrekt einsetzen. dann funktioniert alles einwandfrei.
ich habs jetzt so gelöst:Private Declare Function GetWindowThreadProcessId Lib "user32.dll" (ByVal hWnd _
As Long, ByRef lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32.dll" (ByVal dwDesiredAccess _
As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32.dll" (ByVal hProcess As _
Long, ByVal uExitCode As Long) As Long
Private Declare Function CloseHandle Lib "kernel32.dll" (ByVal hObject As Long) _
As Long
Private Const PROCESS_TERMINATE As Long = (&H1)
Private Declare Function WaitForSingleObject Lib _
"kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Const INFINITE = 1000
Private Const SYNCHRONIZE = &H100000
Private Function WaitForProceed(ByVal sFile As String, _
ByVal wStyle As VbAppWinStyle) As Long
Dim taskID As Long
Dim Handle As Long
taskID = Shell(sFile, wStyle)
WaitForProceed = taskID
Handle = OpenProcess(SYNCHRONIZE, False, taskID)
Call WaitForSingleObject(Handle, INFINITE)
Call CloseHandle(Handle)
End Function
Public Sub PrintFile(sFile As String)
Dim ap As String
' Pfad Des Acrobat Readers emitteln:
ap = RegRead("HKEY_CLASSES_ROOT\AcroExch.Document.7\shell\Print\command\")
' Wenn du einen anderen Dateityp drucken willst musst du natürlich den
' auszulesenden Pfad
' hier ändern
' Mit deinem Dateipfad füllen:
ap = Replace(ap, "%1", sFile)
Dim h As Long
h = Shell(ap, vbNormalFocus)
WaitForProceed ap, vbNormalFocus
GetWindowThreadProcessId h, h
h = OpenProcess(PROCESS_TERMINATE, True, h)
TerminateProcess h, 0
CloseHandle h
End Sub
Private Function RegRead(Path As String) As String
Dim ws As Object
On Error GoTo ErrHandler
Set ws = CreateObject("WScript.Shell")
RegRead = ws.RegRead(Path)
Exit Function
ErrHandler:
RegRead = ""
End Function
Private Sub Command1_Click()
PrintFile App.path & "\data\TEST.pdf"
End Sub Die Verzögerung habe ich auf 1 Sekunde (1000 MIllisekunden gestellt), damit auch auf langsamen Rechnern genug Zeit zum Öffnen und Senden des Druckauftrages bleibt.
Liebe grüße
Sven
Dinge sind nur solange unm?glich, bis sie es nicht mehr sind. |