imaginad que ejecutamos un comando en una ventana dos. Por ejemplo 'powercfg /list'
existe alguna manera programáticamente de saber que el comando se ha terminado de ejecutar ? O sea, que el sistema ha terminado de ejecutar dicho comando.
He intentado waiforsingleoject sin éxito.
Los comandos son programas normales que cuando terminan devuelven el control al programa que les llamo. Para los programas que no funcionan en segundo plano solo se me ocurre ver si cuando termina un comando te devuelve la ruta actual o no.
Saludos.
http://stackoverflow.com/questions/5685972/how-to-wait-for-a-shell-process-to-finish-before-executing-further-code-in-vb6 (http://stackoverflow.com/questions/5685972/how-to-wait-for-a-shell-process-to-finish-before-executing-further-code-in-vb6)
no sirve amigos...
cuando se usa el waitforsingleobject infinite, desde nuestro programa, estamos esperando para siempre y pasamos de ahí.
Tenes que usar el waitforsingleobject tienes que asegurarte que el proceso no se interrumpe en ningun momento (ej: que no aparezca el "presione una tecla para continuar...")
Encontre esto en mi biblioteca de codigos
Private Const SW_HIDE = 0
Private Const WAIT_TIMEOUT = &H102
Private Declare Function ShellExecuteExA Lib "shell32" (lpExecInfo As SHELLEXECUTEINFO) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle As Long, ByVal dwMilliseconds As Long) As Long
Private Type SHELLEXECUTEINFO
cbSize As Long
fMask As Long
hwnd As Long
lpVerb As String
lpFile As String
lpParameters As String
lpDirectory As String
nShow As Long
hInstApp As Long
lpIDList As Long
lpClass As String
hkeyClass As Long
dwHotKey As Long
hIcon As Long
hProcess As Long
End Type
Public Sub ShellWait(ByVal sFile As String, ByVal sParams As String, ByVal sDir As String)
Dim Retval As Long, ShExInfo As SHELLEXECUTEINFO
With ShExInfo
.cbSize = Len(ShExInfo)
.fMask = 0
.hwnd = 0
.lpVerb = "open"
.lpFile = sFile
.lpParameters = sParams
.lpDirectory = sDir
.nShow = SW_HIDE
End With
Retval = ShellExecuteExA(ShExInfo)
If Retval = 0 Then
Call MsgBox("Error :(")
Else
Do
DoEvents
Loop Until WaitForSingleObject(ShExInfo.hProcess, 0) < WAIT_TIMEOUT
End If
End Sub