
Running a program after another using shell statement
Quote:
> Hi there,
> I'm running a program with the shell statement (e.g. shell
("c:\test.exe"))
> and i want to run another program, but just when the first one ends.
> Does anyone can help me with this?!
> Thanks in advance.
I'm not sure where I found this function but it does the trick.
Public Function ExecCmd(Cmdline$) As Boolean
On Error GoTo 10
Dim phnd&, ret&
' Use Shell fn to launch, get a process handle
ret& = Shell(Cmdline$, vbNormalFocus)
If (ret& <> 0) Then
' Open the process, using handle retrieved from Shell
phnd& = OpenProcess(SYNCHRONIZE, 0, ret&)
If (phnd& <> 0) Then
' If OpenProc was successful, wait for the object to finish
Call WaitForSingleObject(phnd&, INFINITE)
' Close the object
Call CloseHandle(phnd&)
End If
ret& = phnd&
End If
ExecCmd = CBool(ret&)
GoTo 20
10 ExecCmd = False
Resume 20
20
End Function