Shell

How do I pause the execution of my program durring a shell() function?
rtcompAsked:
Who is Participating?
 
vettrangerConnect With a Mentor Commented:
The absolute easiest way is with a message box :

msgbox "Click OK when (shelled function) has completed",,"Status"

If your shelled function is going to run for a fairly predictable time, another very simple way is to put a for:next loop after it.

If the shelled program produces an output file then :

Shell "Something"
a$=""
Filename$ = "path\filename"
do until a$ > ""
   a$=dir(FileName$)
loop

If you know the Windows description of the shelled app :

dim ShellApp as boolean
ShellAppFound = false

hWnd& = GetDesktopWindow()
hWnd& = GetWindow(hWnd&, GW_CHILD)
while ShellAppFound = false

Do
If IsWindowEnabled&(hWnd&) And IsWindowVisible&(hWnd&) Then
   temp$ = GetWindowDesc$(hWnd&)
   If InStr(temp$, "YourAppName") Then ShellAppFound = true
end if
Loop While hWnd& <> 0

wend
0
 
KDivadCommented:
Take a look at CreateProcess instead of Shell and use WaitForSingleObject. I don't know how they work or I'd tell you, but this is pretty much the normal way it is done.
0
 
mark2150Commented:
Here is code for ExecCmd. It will spawn child process and wait for it to complete.

'
' These data type declarations are required to support the obscure windows
' function to spawn a child task and wait for it to finish before continuing
'
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
'
Private 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
'
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
'
Const NORMAL_PRIORITY_CLASS = &H20&
Const INFINITE = -1&
'

Public Sub ExecCmd(cmdline$)
'
' This executes an external windows program and waits for it to complete
'
Dim proc As PROCESS_INFORMATION
Dim start As STARTUPINFO
'
' Initialize the STARTUPINFO structure:
'
start.cb = Len(start)
'
' Start the shelled application
'
ret& = CreateProcessA(0&, cmdline$, 0&, 0&, 1&, NORMAL_PRIORITY_CLASS, 0&, 0&, start, proc)
'
' Wait for the shelled application to finish:
'
holdhere:
    DoEvents
    ret& = WaitForSingleObject(proc.hProcess, 5000)
    If ret& <> 0 Then GoTo holdhere
'
ret& = CloseHandle(proc.hProcess)
End Sub


This, and a lot more, is online on my web page: www.cyberchute.com/rvbus/madmark

M

0
 
rtcompAuthor Commented:
That is the easiest  way.

Thanks
0
 
vettrangerCommented:
Happy to help. :-)
0
All Courses

From novice to tech pro — start learning today.