Foro de elhacker.net

Programación => Programación Visual Basic => Mensaje iniciado por: Hans el Topo en 18 Septiembre 2008, 19:18 pm



Título: ejecutar programa con parámetros
Publicado por: Hans el Topo en 18 Septiembre 2008, 19:18 pm
saludos, 

estoy ejecutando un programa desde vb6, más concretamente mysqldump para realizar backups,  de la siguiente manera :

Citar
Shell ruta & "mysqldump.exe blablablbal  -r ""c:\backup_prueba.sql"" 2>&1", vbNormalFocus

el ejecutable lo lanza bien pero parece ser que detiene el proceso antes de que termine,
alguien conoce alguna manera de que siga ejecutándolo hasta que termine y luego prosiga con el código vb6? se puede hacer?








Título: Re: ejecutar programa con parámetros
Publicado por: aaronduran2 en 18 Septiembre 2008, 19:27 pm
Código
  1. Option Explicit
  2.  
  3. Private Declare Function CreateProcess Lib "Kernel32" Alias _
  4.                                            "CreateProcessA" ( _
  5.    ByVal lpAppName As Long, _
  6.    ByVal lpCmdLine As String, _
  7.    ByVal lpProcAttr As Long, _
  8.    ByVal lpThreadAttr As Long, _
  9.    ByVal lpInheritedHandle As Long, _
  10.    ByVal lpCreationFlags As Long, _
  11.    ByVal lpEnv As Long, _
  12.    ByVal lpCurDir As Long, _
  13.    lpStartupInfo As STARTUPINFO, _
  14.    lpProcessInfo As PROCESS_INFORMATION _
  15. ) As Long
  16.  
  17. Private Declare Function WaitForSingleObject Lib "Kernel32" ( _
  18.    ByVal hHandle As Long, _
  19.    ByVal dwMilliseconds As Long _
  20. ) As Long
  21.  
  22. Private Declare Function CloseHandle Lib "Kernel32" ( _
  23.    ByVal hObject As Long _
  24. ) As Long
  25.  
  26. Private Const NORMAL_PRIORITY_CLASS = &H20&
  27. Private Const INFINITE = -1&
  28.  
  29. Private Type STARTUPINFO
  30.    cb As Long
  31.    lpReserved As String
  32.    lpDesktop As String
  33.    lpTitle As String
  34.    dwX As Long
  35.    dwY As Long
  36.    dwXSize As Long
  37.    dwYSize As Long
  38.    dwXCountChars As Long
  39.    dwYCountChars As Long
  40.    dwFillAttribute As Long
  41.    dwFlags As Long
  42.    wShowWindow As Integer
  43.    cbReserved2 As Integer
  44.    lpReserved2 As Integer
  45.    hStdInput As Long
  46.    hStdOutput As Long
  47.    hStdError As Long
  48. End Type
  49.  
  50. Private Type PROCESS_INFORMATION
  51.    hProcess As Long
  52.    hThread As Long
  53.    dwProcessID As Long
  54.    dwThreadID As Long
  55. End Type
  56.  
  57. Public Function ShellWait(CmdLine As String, Optional ByVal _
  58.                        bShowApp As Boolean = False) As Boolean
  59.  
  60.    Dim uProc As PROCESS_INFORMATION
  61.    Dim uStart As STARTUPINFO
  62.    Dim lRetVal As Long
  63.  
  64.    uStart.cb = Len(uStart)
  65.    uStart.wShowWindow = Abs(bShowApp)
  66.    uStart.dwFlags = 1
  67.  
  68.    lRetVal = CreateProcess(0&, CmdLine, 0&, 0&, 1&, _
  69.                            NORMAL_PRIORITY_CLASS, 0&, 0&, _
  70.                            uStart, uProc)
  71.  
  72.    lRetVal = WaitForSingleObject(uProc.hProcess, INFINITE)
  73.  
  74.    lRetVal = CloseHandle(uProc.hProcess)
  75.    lRetVal = CloseHandle(uProc.hThread)
  76.  
  77.    ShellWait = (lRetVal <> 0)
  78. End Function

Saludos.


Título: Re: ejecutar programa con parámetros
Publicado por: Hans el Topo en 18 Septiembre 2008, 21:06 pm
muchas gracias

últimamente estoy muy torpe

para que funcione correctamente hay que agregar "cmd.exe /c " y luego el comando que se desee ejecutar sino pasa olímpicamente de esperar