Giovani Insieme: il sogno di Don Bosco Giovani Insieme
il sogno di Don Bosco

scarica l'MP3!

 

Jonathan Livingston Seagull Project Il Gabbiano
Jonathan Livingston


Ascolta le musiche!

 

E la strada si apre E la strada si apre
Gen Arcobaleno

Ascolta il nuovo arrangiamento

Print this page

Avviare applicazioni da VB6 tramite la Shell in modalità sincrona

chiamata:

ret = ShellandWait(path_completo_applicazione)

codice:

Option Explicit
 
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, _
ByVal dwProcessId As Long) As Long
 
Private Declare Function GetExitCodeProcess Lib "kernel32" _
(ByVal hProcess As Long, lpExitCode As Long) As Long
 
Private Const STATUS_PENDING = &H103&
Private Const PROCESS_QUERY_INFORMATION = &H400 


Public Function ShellandWait(ExeFullPath As String, _
Optional TimeOutValue As Long = 0) As Boolean
     
    Dim lInst As Long
    Dim lStart As Long
    Dim lTimeToQuit As Long
    Dim sExeName As String
    Dim lProcessId As Long
    Dim lExitCode As Long
    Dim bPastMidnight As Boolean
     
    On Error GoTo ErrorHandler
 
    lStart = CLng(Timer)
    sExeName = ExeFullPath
 
    'Deal with timeout being reset at Midnight
    If TimeOutValue > 0 Then
        If lStart + TimeOutValue < 86400 Then
            lTimeToQuit = lStart + TimeOutValue
        Else
            lTimeToQuit = (lStart - 86400) + TimeOutValue
            bPastMidnight = True
        End If
    End If
 
    lInst = Shell(sExeName, 1)
     
lProcessId = OpenProcess(PROCESS_QUERY_INFORMATION, False, lInst)
 
    Do
        Call GetExitCodeProcess(lProcessId, lExitCode)
        DoEvents
        If TimeOutValue And Timer > lTimeToQuit Then
            If bPastMidnight Then
                 If Timer < lStart Then Exit Do
            Else
                 Exit Do
            End If
    End If
    Loop While lExitCode = STATUS_PENDING
     
    ShellandWait = True
    
ErrorHandler:
ShellandWait = False
Exit Function
End Function


Link:

http://www.freevbcode.com/ShowCode.Asp?ID=99