Results 1 to 6 of 6

Thread: Finding out if a batch file is still running

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 1999
    Location
    Lincolnshire, UK
    Posts
    111
    I am having to run a batch file to communicate with an AS400 (this cannot be changed) and I want to find out when the batch file has finished

    Any help would be appricated

    Cheers

    Chris

  2. #2
    Member
    Join Date
    Jun 2000
    Location
    North of France
    Posts
    49

    Lightbulb

    A MacGyver tip

    Create a temporary file when your batch file start.
    Delete it when your batch file has finish.

    In your VB code, look for the temporary file. If it's still there, you batch isn't finish. If it's not there, then your batch has finish.

    I've just looking for an API to get the process name but i didn't find one.

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367
    I am not sure how you want to know when it finishes. Do you want to keep your program running, or wait for the batch file to finish before your program continues?

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    You can start the batchfile with CreateProcess. This returns a process handle. With this processHandle you can call WaitForSingleObject to check if the job is finished. When I get home I will look for a sample, the samples I have here (at work) are to mixed up in other code.


  5. #5
    New Member
    Join Date
    May 2000
    Location
    sweden
    Posts
    5
    This will hold your application up while waiting for the batchfile to finish:


    in a Module:

    Private Type STARTUPINFO
    cb As Long
    lpReserved As String
    lpDesktop As String
    lpTitle As String
    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

    Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long

    Declare Function CreateProcessA Lib "kernel32" (ByVal lpApplicationName As Long, ByVal lpCommandLine As String, ByVal lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As Long, lpStartupInfo As STARTUPINFO, lpProcessInformation As PROCESS_INFORMATION) As Long
    Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

    Private Const NORMAL_PRIORITY_CLASS = &H20&
    Private Const INFINITE = -1&

    '*** Call this function with the batchfile as the filename argument
    Public Sub ExecApp(FileName$)
    Dim ProcInfo As PROCESS_INFORMATION
    Dim StartInfo As STARTUPINFO

    StartInfo.cb = Len(StartInfo)

    'Start the specified application
    ret& = CreateProcessA(0&, FileName$, 0&, 0&, 1&, _
    NORMAL_PRIORITY_CLASS, 0&, 0&, StartInfo, ProcInfo)

    'Hold on for app to finish
    ret& = WaitForSingleObject(ProcInfo.hProcess, INFINITE)
    ret& = CloseHandle(ProcInfo.hProcess)
    End Sub


    In your form:

    Private Sub Form_Load()
    Call ExecApp("c:\thabatch.bat")
    MsgBox "Finished!"
    End Sub


    have a nice day =)

    /matse

  6. #6
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Private Declare Function ShellExecute Lib _
    "shell32.dll" Alias "ShellExecuteA" _
    (ByVal hwnd As Long, ByVal lpOperation As String, _
    ByVal lpFile As String, ByVal lpParameters As String, _
    ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
    
    'Use this line in click event (substitute the URL for your own):
    'call the bat file this way..it exposes the dos shell and
    'then closes it when it is finished it's thing.
    
    
    Private Sub Command1_Click()
    
        Dim h As Long
        h = Shell(Environ("COMSPEC") & " /C C:\yourfile.bat")
        DoEvents
     
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width