Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 338
  • Last Modified:

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
0
willwatters
Asked:
willwatters
1 Solution
 
rettiseertCommented:
AutoIt can compile scripts into EXE files. Compile your script and then execute it using something like this

    Dim WshShell As Object
    Set WshShell = CreateObject("WScript.Shell")
   
    Me.Enabled = False
    WshShell.Run "C:\Development\AutoIt\Test3_MSOutlook.exe", , True
    Me.Enabled = True

Now the program will stop while Test3_MSOutlook.exe is runing. I dont know if you can use this without compiling the script (using au3 extension) but try.
0
 
PaulHewsCommented:
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
0

Featured Post

[Webinar] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now