Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Exiting a Process
Message
De
05/11/2001 19:40:09
Jason Dalio
Northern Interior Regional Health Board
Prince George, Colombie Britannique, Canada
 
Information générale
Forum:
Visual Basic
Catégorie:
Fonctions API de Windows
Divers
Thread ID:
00577723
Message ID:
00577727
Vues:
30
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
Fil
Voir

Click here to load this message in the networking platform