Esta es la funcion que yo uso, podes evitar el loop inifinito un algunas 
modificaciones.

***
* Function ShellWait
*    Ejecuta un proceso y espera a que finalice
***
Function ShellWait(cEXEFile, cCommandLine, nWindow)
Local cStartupInfo, cProcInfo, nProcess


* defines
#define STARTF_USESHOWWINDOW    1

#define m0                    256
#define m1                  65536
#define m2               16777216


* Validaciones
If Type("nWindow") <> "N"
   nWindow = SW_SHOWMAXIMIZED
Endif


* Declare WinAPI Functions
Declare Short CreateProcess in WIN32API ;
              String lpszModuleName, ;
              String @lpszCommandLine, ;
              String lpSecurityAttributesProcess, ;
              String lpSecurityAttributesThread, ;
              Short bInheritHandles, ;
              Integer dwCreateFlags, ;
              String lpvEnvironment, ;
              String lpszStartupDir, ;
              String @lpStartInfo, ;
              String @lpProcessInfo

Declare Integer WaitForSingleObject in kernel32 ;
        Integer hHandle,; 
        Integer dwMilliseconds 

Declare Integer CloseHandle in kernel32 ;
        Integer hObject 

Declare Integer GetLastError in kernel32


* Incializar estructuras
cStartupInfo = num2dword(68) + ;
               num2dword(0) + num2dword(0) + num2dword(0) + ; 
               num2dword(0) + num2dword(0) + num2dword(0) + num2dword(0) + ; 
               num2dword(0) + num2dword(0) + num2dword(0) + ; 
               num2dword(STARTF_USESHOWWINDOW) + ; 
               num2word(nWindow) + ;
               num2word(0) + num2dword(0) + ;
               num2dword(0) + num2dword(0) + num2dword(0) 

cProcInfo = Replicate(Chr(0), 16) 


* Ejecutar comando
If !Empty(cCommandLine)
   cEXEFile = cEXEFile + cCommandLine
Endif

If CreateProcess(0, cEXEFile, 0, 0, 0, 0, 0, JustPath(cEXEFile), @cStartupInfo, 
@cProcInfo) == 0

   * Posibles errores
   *  2 = The system cannot find the file specified 
   *  3 = The system cannot find the path specified 
   * 87 = ERROR_INVALID_PARAMETER 
   MessageBox("Error número: " + LTrim(Str(GetLastError())), 64, "Error")

else
   * Esperar a que termine
   nProcess = buf2dword(SUBSTR(cProcInfo, 1, 4)) 
   WaitForSingleObject(nProcess, -1)
   CloseHandle(nProcess)
Endif

EndFunc



***
* Function num2dword
*    Funcion auxiliar a ShellWait
***
Function num2dword(nValue) 
Local b0, b1, b2, b3 

b3 = Int(nValue/m2) 
b2 = Int((nValue - b3 * m2)/m1) 
b1 = Int((nValue - b3*m2 - b2*m1)/m0) 
b0 = Mod(nValue, m0) 

Return(Chr(b0) + Chr(b1) + Chr(b2) + Chr(b3))



***
* Function num2word
*    Funcion auxiliar a ShellWait
***
Function num2word(nValue) 
Return(Chr(Mod(nValue, 256)) + Chr(Int(nValue / 256)))



***
* Function buf2dword
*    Funcion auxiliar a ShellWait
***
Function buf2dword(cBuffer) 
Return(Asc(SubStr(cBuffer, 1, 1)) + ; 
       Asc(SubStr(cBuffer, 2, 1)) * 256 + ; 
       Asc(SubStr(cBuffer, 3, 1)) * 65536 + ; 
       Asc(SubStr(cBuffer, 4, 1)) * 16777216)

  ----- Original Message ----- 
  From: PabloC 
  To: GUFA List Member 
  Sent: Monday, December 10, 2007 1:34 PM
  Subject: [GUFA] ShellExecute


  Gracias Jose
  Puedo tener control sobre el proceso externo, pero no queria llegar a eso, x 
que puede ser un loop infinito si ese archivo por algun motivo no se creo y 
deberia tambien controlar eso.
  Pensaba en algo mas eficiente

  Saludos
  PabloC
    ----- Original Message ----- 
    From: Jose Cardaropoli 
    To: GUFA List Member 
    Sent: Monday, December 10, 2007 1:31 PM
    Subject: [GUFA] ShellExecute


    Si tenes control del proceso externo , podes decir que cree una archivo 
culaquiera "esperando.txt" y de este lado mantener la aplicación mientras este 
archivo exista, antes de finalizar aquel proceso lo elimina y libera la 
aplicación de este lado.

    Si no tenes control sobre el proceso externo, no sé, porque son procesos 
asincronicos...

    Saludos
    José Cardaopoli
      ----- Original Message ----- 
      From: PabloC 
      To: GUFA List Member 
      Sent: Monday, December 10, 2007 12:49 PM
      Subject: [GUFA] ShellExecute


      Gente
      Como puede con el ShellExecute disparar un proceso externo y esperar a 
que termine para seguir?

      Saludos
      PabloC


      __________ Información de NOD32, revisión 2712 (20071209) __________

      Este mensaje ha sido analizado con NOD32 antivirus system
      http://www.nod32.com

Responder a