Link to home
Start Free TrialLog in
Avatar of willwatters
willwatters

asked on

Code to wait until a separate testing program/application has completed before continuing

In VB control code I call a file/script of a different programming language - free ware program called AutoIt.  This file/script will open an application (i.e. Outlook) and test it.  What is the code to wait until this script has finished so the VB control pannel can carry on with the next stage of the program? I don't think I can pass paramaters into and out of the script.

I was thinking of getting the Process Image Name (Task Manager) of the application that has run and wait until it has finished/process name does not exist anymore (once the application is closed the script is finished) - before continuing with the VB code, for the next test.

Please amend the following code to make this possible:

'Call AutoIt Outlook Test
    Call oTest.OpenFile("C:\Development\AutoIt\Test3_MSOutlook.au3")
   
    Sleep 8000
   
    'Need code to check if OUTLOOK.EXE exists (Outlook process image name).  
    'If so assign it to PIName variable
   
    'If MS Outlook opened/OUTLOOK.EXE exists, wait until the test is over before proceeding.
    'Please amend this code if necessary
    If PIName = "OUTLOOK.EXE" Then
        'While  OUTLOOK.EXE/MS Outlook is still running
            'Wait until MS Outlook is closed and it is finished testing
        Wend
        Sleep 2000
    Else
        oErrLog.LogError Pre, eTests.Test3, "MS Outlook", "MS Outlook failed to open", Err.Number
        Err.Clear
    End If
ASKER CERTIFIED SOLUTION
Avatar of rettiseert
rettiseert

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Here's a function that can test if outlook is running:

Option Explicit

Const TH32CS_SNAPHEAPLIST = &H1
Const TH32CS_SNAPPROCESS = &H2
Const TH32CS_SNAPTHREAD = &H4
Const TH32CS_SNAPMODULE = &H8
Const TH32CS_SNAPALL = (TH32CS_SNAPHEAPLIST Or TH32CS_SNAPPROCESS Or TH32CS_SNAPTHREAD Or TH32CS_SNAPMODULE)
Const TH32CS_INHERIT = &H80000000

Private Type PROCESSENTRY32
    dwSize As Long
    cntUsage As Long
    th32ProcessID As Long
    th32DefaultHeapID As Long
    th32ModuleID As Long
    cntThreads As Long
    th32ParentProcessID As Long
    pcPriClassBase As Long
    dwFlags As Long
    szExeFile As String * 260
End Type
Private Declare Function CreateToolhelp32Snapshot Lib "Kernel32" (ByVal lFlags As Long, ByVal lProcessID As Long) As Long
Private Declare Function Process32First Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Function Process32Next Lib "Kernel32" (ByVal hSnapShot As Long, uProcess As PROCESSENTRY32) As Long
Private Declare Sub CloseHandle Lib "Kernel32" (ByVal hPass As Long)


Private Function IsProcessRunning(strProcessModule As String) As Boolean

    Dim lngSnapShot As Long
    Dim ProcessEntry As PROCESSENTRY32
    Dim lngRet As Long
    Dim bRet As Boolean
   
    lngSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0)
    ProcessEntry.dwSize = Len(ProcessEntry)
    lngRet = Process32First(lngSnapShot, ProcessEntry)

    Do While lngRet > 0
        If InStr(1, ProcessEntry.szExeFile, strProcessModule, vbTextCompare) > 0 Then
            bRet = True
            Exit Do
        End If
        lngRet = Process32Next(lngSnapShot, ProcessEntry)
    Loop
    'close our snapshot handle
    CloseHandle lngSnapShot
    IsProcessRunning = bRet
End Function

Private Sub Command1_Click()
    MsgBox IsProcessRunning("OUTLOOK.EXE")
End Sub