Tema: FAQ's de VB6
Ver Mensaje Individual
  #125 (permalink)  
Antiguo 01/02/2006, 10:43
Avatar de VisualGuallabo
VisualGuallabo
 
Fecha de Ingreso: marzo-2005
Mensajes: 288
Antigüedad: 19 años, 1 mes
Puntos: 2
Ejecutar un programa y esperar que finalice

'en un from
Option Explicit

Private Const PROCESS_QUERY_INFORMATION = &H400
Private Const STILL_ACTIVE = &H103
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess&, ByVal bInheritHandle&, ByVal dwProcessId&) _
As Long
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) _
As Long

Sub EsperarShell(sCmd As String)

Dim hShell As Long
Dim hProc As Long
Dim codExit As Long

' ejecutar comando
hShell = Shell(Environ$("Comspec") & " /c " & sCmd, 2)

' esperar a que se complete el proceso
hProc = OpenProcess(PROCESS_QUERY_INFORMATION, False, hShell)

Do
GetExitCodeProcess hProc, codExit
DoEvents
Loop While codExit = STILL_ACTIVE

End Sub
'Ejemplo
Private Sub Command1_Click()
EsperarShell ("calc.exe")
msgbox "termino"
End Sub
__________________
"No hay lenguaje de programación potente que sea inferior a otro semejante cuando existe un buen programador que lo defiende"

Yosvanis Cruz Alias VisualGuallabo
Ycruz