Information générale
Catégorie:
Fonctions API de Windows
I have done something simloiar in one of my programs and have posted what I used. My chopped example below runs a DOS-based program and holds the VB execution until the program is finished running at which point it terminates the shelled app. I think all you are missing is the CloseHandle API but I put the rest of the code here just in case.
Const SYNCHRONIZE = &H100000
Const INFINITE = &HFFFF
'Wait forever
Const WAIT_OBJECT_0 = 0
'The state of the specified object is signaled
Const WAIT_TIMEOUT = &H102
'The time-out interval elapsed & the object’s state
'is nonsignaled.
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, _
ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub Form_Load
Dim lPid As Long
Dim lRet As Long
Dim lHnd As Long
lPid = Shell(CommandLine, vbHide)
If lPid <> 0 Then
'Get a handle to the shelled process.
lHnd = OpenProcess(SYNCHRONIZE, 0, lPid)
'If successful, wait for the application to end and close the handle.
If lHnd <> 0 Then
lRet = WaitForSingleObject(lHnd, INFINITE)
CloseHandle (lHnd)
End If
End If
End Sub
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement