Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Shell

Posted on 1999-07-28
5
Medium Priority
?
288 Views
Last Modified: 2010-04-30
How do I pause the execution of my program durring a shell() function?
0
Comment
Question by:rtcomp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 8

Accepted Solution

by:
vettranger earned 400 total points
ID: 1528139
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
 
LVL 5

Expert Comment

by:KDivad
ID: 1528140
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
 
LVL 12

Expert Comment

by:mark2150
ID: 1528141
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
 

Author Comment

by:rtcomp
ID: 1528142
That is the easiest  way.

Thanks
0
 
LVL 8

Expert Comment

by:vettranger
ID: 1528143
Happy to help. :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question