Skip to main content

Executing an External Program From WinWrap


Question / Problem: 

How can an external program be executed from within a KTM project's script?

Answer / Solution: 

Sample of executing external code and not waiting for it to finish:

Private Sub ExecuteCommandWithoutWaiting(Command As String, ShowWindow As Boolean)
   If ShowWindow Then
      Shell(Command, vbNormalFocus)
      Shell(Command, vbHide)
   End If
End Sub

Sample of executing extneral code and waiting for the command to finish:

Private Const WAIT_INFINITE = -1&
Private Const SYNCHRONIZE = &H100000

Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
                                                     ByVal bInheritHandle As Long, _
                                                     ByVal dwProcessId As Long) As Long

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

Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long

Private Sub ExecuteCommandWithWaiting(Command As String, ShowWindow As Boolean)

   Dim hProcess As Long
   Dim TaskId As Long
   If ShowWindow Then
      TaskId = Shell(Command, vbNormalFocus)
      TaskId = Shell(Command, vbHide)
   End If
   hProcess = OpenProcess(SYNCHRONIZE, True, TaskId)
   Call WaitForSingleObject(hProcess, WAIT_INFINITE)
   CloseHandle hProcess
End Sub


Applies to:  

Product Version Category
KTM 6.3 Scripting
KTM 6.2 Scripting



From legacy Kofax KnowledgeBase QAID 17336: Execute an External Program

  • Was this article helpful?