|
-
Nov 26th, 2000, 06:15 PM
#1
Thread Starter
Lively Member
I am using the shell function to run an external .exe file.
How can I determine when the shell program ends?
I know that in vb6 it is possible to use CreateProcessA API
to solve this problem.
I have vb5.
Is there a nother way to solve this problem?
Thanks.
Dan.
-
Nov 26th, 2000, 09:47 PM
#2
Use this as your Shell function and you will be able to tell when the program has ended.
Code:
Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
Const STILL_ACTIVE = &H103
Const PROCESS_QUERY_INFORMATION = &H400
'JobtoDo - Program to run
Sub Shell32Bit(ByVal JobToDo As String)
Dim hProcess As Long
Dim RetVal As Long
'The next line launches JobToDo as icon,
'captures process ID
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1))
Do
'Get the status of the process
GetExitCodeProcess hProcess, RetVal
'Sleep command recommended as well as DoEvents
DoEvents: Sleep 100
'Loop while the process is active
Loop While RetVal = STILL_ACTIVE
Msgbox "App has been unloaded!"
End Sub
Usage
Private Sub Command1_Click()
Call Shell32Bit("C:\App\App.exe")
End Sub
-
Nov 27th, 2000, 01:20 AM
#3
Or you could use the Windows Script Host, which has a run function that waits until the process has finished before continuing
- gaffa
-
Nov 27th, 2000, 09:18 AM
#4
Thread Starter
Lively Member
Thanks for the usefull answers.
Gaffa,
Could you Alabirate on your suggestion?
Thanks.
Dan.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|