Newsgroup: it.comp.lang.visual-basic
Titolo: Attendere fine processo

Ciao,
volevo saper se qualcuno sa come aiutarmi.
Uso l'api ShellExecute da vb6 per lanciare un programma esterno e vorrei che
il codice si bloccasse in quel punto fino a che il progr. esterno non si sia
chiuso....
C'e' un metodo per fare questo?
Grazie a tutti

no. al massimo puoi rilevare se l'exe che hai lanciato si è chiuso.
bye
-- 
Esistono 10 tipi di persone: chi conosce il binario e chi no.
www.nicolaottomano.it

 ha scritto nel messaggio
news:ctEQb.4823$VS6....@tornado.fastwebnet.it...


Alex wrote:

Potresti usare ShellExecuteEx e WaitForSingleObject. Ho buttato giu' un
esempio:
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
Const INFINITE = &HFFFF
Const SW_SHOW = &H5
Private Declare Function ShellExecuteEx Lib "shell32.dll" Alias
"ShellExecuteEx" (shInfo As SHELLEXECUTEINFO) As Long
Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal hHandle
As Long, ByVal dwMilliseconds As Long) As Long
Sub ExecuteAndWait(FileName As String, OwnerhWnd As Long)
    Dim shInfo As SHELLEXECUTEINFO
    With shInfo
        .cbSize = Len(shInfo)
        .fMask = SEE_MASK_NOCLOSEPROCESS
        .hwnd = OwnerhWnd
        .lpVerb = "open"
        .lpFile = FileName
        .lpParameters = vbNullChar
        .lpDirectory = vbNullChar
        .nShow = SW_SHOW
        .hInstApp = 0
        .lpIDList = 0
    End With
    If ShellExecuteEx(shInfo) <> 0 then
        WaitForSingleObject(shInfo.hProcess, INIFINITE)
    End If
End Sub
Ciao
Michele

"Alex"
'*.vbs
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("calc")
Do While oExec.Status = 0
     WScript.Sleep 100
Loop
WScript.Echo "stato" & oExec.Status &"     "  &"programma chiuso"
'VB >> 1 command button
http://www.allapi.net/cgi-bin/redirect.cgi?place=apiguide
Private Type STARTUPINFO
      cb As Long
      lpReserved As String
      lpDesktop As String
      lpTitle As String
      dwX As Long
      dwY As Long
      dwXSize As Long
      dwYSize As Long
      dwXCountChars As Long
      dwYCountChars As Long
      dwFillAttribute As Long
      dwFlags As Long
      wShowWindow As Integer
      cbReserved2 As Integer
      lpReserved2 As Long
      hStdInput As Long
      hStdOutput As Long
      hStdError As Long
   End Type
   Private Type PROCESS_INFORMATION
      hProcess As Long
      hThread As Long
      dwProcessID As Long
      dwThreadID As Long
   End Type
   Private Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
      hHandle As Long, ByVal dwMilliseconds As Long) As Long
   Private Declare Function CreateProcessA Lib "kernel32" (ByVal _
      lpApplicationName As String, ByVal lpCommandLine As String, ByVal _
      lpProcessAttributes As Long, ByVal lpThreadAttributes As Long, _
      ByVal bInheritHandles As Long, ByVal dwCreationFlags As Long, _
      ByVal lpEnvironment As Long, ByVal lpCurrentDirectory As String, _
      lpStartupInfo As STARTUPINFO, lpProcessInformation As _
      PROCESS_INFORMATION) As Long
   Private Declare Function CloseHandle Lib "kernel32" _
      (ByVal hObject As Long) As Long
   Private Declare Function GetExitCodeProcess Lib "kernel32" _
      (ByVal hProcess As Long, lpExitCode As Long) As Long
   Private Const NORMAL_PRIORITY_CLASS = &H20&
   Private Const INFINITE = -1&
   Public Function ExecCmd(cmdline$)
      Dim proc As PROCESS_INFORMATION
      Dim start As STARTUPINFO
      start.cb = Len(start)
      ret& = CreateProcessA(vbNullString, cmdline$, 0&, 0&, 1&, _
         NORMAL_PRIORITY_CLASS, 0&, vbNullString, start, proc)
         ret& = WaitForSingleObject(proc.hProcess, INFINITE)
         Call GetExitCodeProcess(proc.hProcess, ret&)
         Call CloseHandle(proc.hThread)
         Call CloseHandle(proc.hProcess)
         ExecCmd = ret&
   End Function
Private Sub Command1_Click()
Dim retval As Long
      retval = ExecCmd("calc.exe")
      MsgBox "Process Finished, Exit Code " & retval
End Sub
--
Fosco