Newsgroup: it.comp.lang.visual-basic
Titolo: Comando SHELL

Ho utilizzato il comando Shell per avviare un programma eseguibile: tale
programma mi restituisce l'ID
Come faccio a saper quando tale programma a finito l'esecuzione ?
Devo testare l'ID ?
Sono proprio nei guai aiutatemi !

Se non erro sul sito comune c'è un esempio che fa al caso tuo...
altrimenti ecco un esempio scritto da Paolo Berardi (Incollalo nella
sezione dichiarazioni di un modulo e imposta nelle proprietà
dell'oggetto come Startup Object: "Sub Mani".):
Riporto interamente l'esempio, inclusi i diritti dell'autore.
Option Explicit
Public 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
        Public Type PROCESS_INFORMATION
        hProcess As Long
        hThread As Long
        dwProcessID As Long
        dwThreadID As Long
End Type
 
Public Declare Function WaitForSingleObject Lib "kernel32" (ByVal _
        hHandle As Long, ByVal dwMilliseconds As Long) As Long
 
Public Declare Function CreateProcessA Lib "kernel32" (ByVal _
        lpApplicationName As Long, 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 Long,
_
        lpStartupInfo As STARTUPINFO, lpProcessInformation As _
        PROCESS_INFORMATION) As Long
 
Public Declare Function CloseHandle Lib "kernel32" (ByVal _
        hObject As Long) As Long
 
Public Const NORMAL_PRIORITY_CLASS = &H20&
Public Const INFINITE = -1&
'#########################################################
'Funzione per lanciare un programma in sincrono.
'Il programma lanciato in finestra viene 'atteso' per
'tutta la sua durata.
'Una funzione usata per lanciare un programma MS-DOS
'e attendere la sua fine.
'1998 by Berardi Paolo
'Email 
pber...@nt.kjws.com
'#########################################################
Public Sub ShellAndWait(ByVal RunProg As String)
    Dim RetVal As Long
    Dim proc As PROCESS_INFORMATION
    Dim StartInf As STARTUPINFO
 
    StartInf.cb = Len(StartInf)
    'Crea sessione del programma da lanciare
    RetVal = CreateProcessA(0&, RunProg, 0&, 0&, 1&,
NORMAL_PRIORITY_CLASS, 0&, 0&, StartInf, proc)
    RetVal = WaitForSingleObject(proc.hProcess, INFINITE)
    RetVal = CloseHandle(proc.hProcess)
End Sub
Sub main()
    MsgBox "Lancio il Bollo notes e attendo la sua chiusura"
    Call ShellAndWait("notepad.exe")
    MsgBox "Il Blocco notes e' stato chiuso"
End Sub
Ciao,
#sirri#@
tin.it
(togliete "#" dall'indirizzo)

...

Function Suspend(exe As String, Optional shellparm) As Integer
   Dim processid As Long
   Dim hprocess As Long
   Dim exitcode As Long
   Dim parm As Integer
   Dim lRet As Long
   #If Win32 = 1 Then
        Select Case VarType(shellparm)
        Case vbEmpty, vbNull
        parm = vbNormalFocus
        Case vbLong, vbInteger, vbSingle, vbDouble
        parm = shellparm
        Case Else
        parm = vbNormalFocus
        End Select
        processid = Shell(exe, parm)
        hprocess = OpenProcess(PROCESS_QUERY_INFORMATION, False, processid)
        Do
        lRet = GetExitCodeProcess(hprocess, exitcode)
        DoEvents
        DoEvents
        Loop While (exitcode = STILL_ACTIVE)
        CloseHandle (hprocess)
   #End If
End Function




------
Ciao Roberto
Per avviare un programma e attenderne la conclusione, trovi un interessante
progetto di esempio sul sito comune dei programmatori VB,
http://members.xoom.com/it_lang_vb
.
Di nuovo ciao
Marco Minerva
http://www.geocities.com/SiliconValley/Foothills/7260/
http://www.armaditaggia.com/marco