Not a really beautiful code, but should work
Code:
#PROCESS32LIB = 9999
Global NewList Process32.PROCESSENTRY32 () ;global=lame
;********************************************************************************************************
;>= Program name
;=> Program name without path
Procedure.s exe_name(name.s)
u = Len(name)
i = u + 1
While Mid(name, i, 1) <> "\" And i>0
i-1
Wend
ProcedureReturn Right(name,u-i)
EndProcedure
;********************************************************************************************************
;=> Active processus list in Process32 global list
Procedure.l get_process_list()
ClearList(Process32 ())
If OpenLibrary (#PROCESS32LIB, "kernel32.dll")
snap = CallFunction (#PROCESS32LIB, "CreateToolhelp32Snapshot", #TH32CS_SNAPPROCESS, 0)
If snap
Define.PROCESSENTRY32 Proc32
Proc32\dwSize = SizeOf (PROCESSENTRY32)
If CallFunction (#PROCESS32LIB, "Process32First", snap, @Proc32)
AddElement (Process32())
CopyMemory (@Proc32, @Process32(), SizeOf (PROCESSENTRY32))
While CallFunction (#PROCESS32LIB, "Process32Next", snap, @Proc32)
AddElement (Process32 ())
CopyMemory (@Proc32, @Process32(), SizeOf(PROCESSENTRY32))
Wend
EndIf
CloseHandle_ (snap)
EndIf
CloseLibrary (#PROCESS32LIB)
ProcedureReturn #True
Else
ProcedureReturn #False
EndIf
EndProcedure
;********************************************************************************************************
;Wait for the end of a program
; >= Program's name
Procedure.s wait_external_prog( name.s )
;Wait 'til program is in the task list
setup=#False
Repeat
;dd = WindowEvent()
;If dd = 0
Delay(1000)
;EndIf
If get_process_list() = #False
Break
EndIf
ForEach Process32()
a$ = LCase(PeekS (@Process32()\szExeFile))
Debug a$
If exe_name(a$) = name
setup = #True
EndIf
Next
Until setup=#True
;Wait 'til its end
Repeat
;dd=WindowEvent()
;If dd = 0
Delay(1000)
;EndIf
setup = #False
If get_process_list() = #False
Break
EndIf
ForEach Process32()
a$=LCase(PeekS (@Process32 ()\szExeFile))
Debug a$
If exe_name(a$)=name
setup=#True
EndIf
Next
Until setup=#False
EndProcedure
RunProgram("c:\windows\notepad.exe")
wait_external_prog( "notepad.exe" )
See also ProgramRunning() command with RunProgram().