Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

VB6 und Prozesssteuerung

Empfohlene Antworten

Veröffentlicht

Ich starte in meinem VB6 Prog eine Batch-Datei und hab nun das Problem, dass mein Programm erst weiterlaufen darf, wenn die Batch wieder zu is.

Kann mir jemand sagen, wie ich rausfinde, ob die Datei noch geöffnet ist??

Danke.

Ich habe hier ein Code Beispiel gefunden ich hoffe das hilft dir weiter


Option Explicit

Private Declare Function WaitForSingleObject Lib "kernel32" _

       (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

Private Declare Function CreatePipe Lib "kernel32" (phReadPipe _

        As Long, phWritePipe As Long, lpPipeAttributes As Any, _

        ByVal nSize As Long) As Long


Private Declare Function ReadFile Lib "kernel32" (ByVal hFile _

        As Long, ByVal lpBuffer As String, ByVal _

        nNumberOfBytesToRead As Long, lpNumberOfBytesRead As _

        Long, ByVal lpOverlapped As Any) As Long


Private Declare Function CreateProcessA Lib "kernel32" (ByVal _

        lpApplicationName As Long, ByVal lpCommandLine As _

        String, lpProcessAttributes As Any, lpThreadAttributes _

        As Any, ByVal bInheritHandles As Long, ByVal _

        dwCreationFlags As Long, ByVal lpEnvironment As Long, _

        ByVal lpCurrentDirectory As Long, lpStartupInfo As Any, _

        lpProcessInformation As Any) As Long


Private Declare Function CloseHandle Lib "kernel32" (ByVal _

        hObject As Long) As Long


Private Type SECURITY_ATTRIBUTES

  nLength As Long

  lpSecurityDescriptor As Long

  bInheritHandle As Long

End Type


Private Type STARTUPINFO

  cb As Long

  lpReserved As Long

  lpDesktop As Long

  lpTitle As Long

  dwX As Long

  dwY As Long

  dwXSize As Long

  dwYSize As Long

  dwXCountChars As Long

  dwYCountChars As Long

  dwFillAttribute As Long

  dwFlags As Long

  wShowWindow As Integer

  cbReserved2 As Integer

  lpReserved2 As Long

  hStdInput As Long

  hStdOutput As Long

  hStdError As Long

End Type


Private Type PROCESS_INFORMATION

  hProcess As Long

  hThread As Long

  dwProcessID As Long

  dwThreadID As Long

End Type


Const NORMAL_PRIORITY_CLASS = &H20&

Const STARTF_USESTDHANDLES = &H100&

Const STARTF_USESHOWWINDOW = &H1&

Const INFINITE = -1&


Private Sub Command1_Click()

  'Hier den Pfad einer Batchdatei oder einer Konsolenanwendung

  'die eine Ausgabe hat eintragen

  Text1.Text = ExecCmdWait("ipconfig.exe")

End Sub


Public Function ExecCmdWait(cmdline As String) As String


  Dim proc As PROCESS_INFORMATION, Result&, bSuccess As Long

  Dim start As STARTUPINFO

  Dim NameOfProc As PROCESS_INFORMATION

  Dim sa As SECURITY_ATTRIBUTES, hReadPipe As Long, hWritePipe As Long

  Dim Buffer$, L&


    sa.nLength = Len(sa)

    sa.bInheritHandle = 1&

    sa.lpSecurityDescriptor = 0&

    Result = CreatePipe(hReadPipe, hWritePipe, sa, 0)


    If Result = 0 Then

      MsgBox "CreatePipe failed Error!", vbCritical

      Exit Function

    End If


    start.cb = Len(start)

    start.dwFlags = STARTF_USESTDHANDLES + STARTF_USESHOWWINDOW

    start.hStdOutput = hWritePipe



    Result = CreateProcessA(0&, cmdline$, sa, sa, 1&, _

                            NORMAL_PRIORITY_CLASS, 0&, _

                            0&, start, proc)


    If Result <> 1 Then

      MsgBox "CreateProcess failed!", vbCritical

    Else

      Result = WaitForSingleObject(proc.hProcess, INFINITE)


      Buffer = String(2000, Chr$(0))

      bSuccess = ReadFile(hReadPipe, Buffer, Len(Buffer), L, 0&)

      If bSuccess = 1 Then

        ExecCmdWait = Left(Buffer, L)

      Else

        MsgBox "ReadFile failed!", vbCritical

      End If

    End If


    Call CloseHandle(proc.hProcess)

    Call CloseHandle(proc.hThread)

    Call CloseHandle(hReadPipe)

    Call CloseHandle(hWritePipe)

End Function

:eek: :confused:

Das bringt mich leider nicht viel weiter.

Situation:

Ich rufe eine dll auf, die wiederum einen Druckvorgang auslöst.

Dieser ruft per Redirected Port die batch Datei auf.

Die batch ruft dann das Prog auf, auf das ich warten will.

Außer Name des Prozesses hab ich nichts, das ich verwerten könnte.

Problem:

Wie finde ich heraus, ob das Programm noch läuft, oder bereits fertig (geschlossen) ist? :confused:

Ich kann dir jetzt leider kein Beispiel geben, aber wenn du eine BAT-File in MS-Dos modus startest, kannst du eben warten bis die ausführung abgeschlossen ist.

Das geht mit APIis glaub ich. Muss ich wie gesagt nochmal schauen. Wenn jedoch von diesem Batch wiederum andere Prozesse gestartet werden, dann hast du wahrscheinlich keine Möglichkeit diese Prozesse auch noch zu überwachen, aber sogut wiei ch weiss, ist es doch so, dass die Batch-Befehle immer Zeile für Zeile durchgearbeitet werden und Eingabeaufforderung (also MS-Dos ist ja auch kein Multitasking-Umgebung (kommt auch auf das Programm an, was ausgeführt wird..) und auch wenn in diesem Batch-File mehrere Programme ausgeführt werden, wartet das System bis das Programm beendet ist und springt dann zu dem nächsten Befehl...?

grüsse

blear

Führ die Batch halt in nem eigenen Thread aus, ist zwar nicht so elegant

sollte aber funzen...

API: CreateThread

Diablo999

Das geht nicht. Wie und wann die batch gestartet wird, wird vom Drucker gehandelt.

Ich kann nur die dll aufrufen, die wiederum den Druck startet (^^).

In der batch-Datei wird dann ein Programm gestartet (ghost script).

Wenn ghostscript wieder geschlossen ist soll mein Programm weiterlaufen. Eher nicht.

Andere Methode wär ich warte bis der Druckvorgang beendet wurde.

(Das selbe Problem nur ein andrer Prozess)

ruf den Batch Job mit Start /Wait aus die Ausführung wird dann erst vortgesetzt wenn der Job durch ist.

Also:

Start /Wait MeinJob.cmd

Nochmal:

Mein Problem ist, dass VB im Code weiterläuft, bevor das Prog fertig ist.

Das Programm, das ich indirekt (^^) aufrufe erstellt eine Datei (*.pdf).

VB fragt nach dem Aufruf ab, ob die Datei auch wirklich erstellt wurde und bringt eine Fehlermeldung, wenn das nicht der Fall ist.

Das Problem: VB fragt ab, bevor das Programm die Datei erstellen kann. Somit kommt es zu einer falschen Fehlermeldung.

Ich will jetzt prüfen, ob das Programm schon fertig ist und VB solange in einer Schleife warten lassen (DoEvents), bis das Programm geschlossen wurde. Meine Frage ist, wie kriege ich raus, ob das Programm schon beendet wurde oder nicht.

Einziger Ansatzpunkt: Ich kenn den Namen des Prozesses mehr aber nicht.

Ne mögliche Lösung wäre , am Ende des Batchjobs der GostScript startet eine selbstdefinierte Enviromentvariable einen Wert zuzuweisen, und Vb solange warten zu lassen wie sie noch nicht gesetzt ist.

Sicher nicht sehr elegant, aber who cares

hm vieleicht kannst du damit etwas anfangen, also die tasks von windows auslesen und in vb halt mit ner schleife so lange warten bis die batch weg ist

http://www.activevb.de/tipps/vb6tipps/tipp0123.html

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.