Executing an External Program From WinWrap
17336
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) Else 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) Else 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 |