Private Declare Function GetModuleUsage Lib "Kernel32" _
Alias "GetModuleUsage" (ByVal hModule As Integer) _ As Integer Private Const SW_HIDE = 0 '// Normal Window Private Const SW_NORMAL = 1 '// Maximized Window Private Const SW_MAXIMIZE = 3 '// Minimized Window Private Const SW_MINIMIZE = 6 '// Hidden Window Private Sub Command1_Click () Dim lngInst As Long Dim intStart As Integer Dim blnTimeOut As Boolean On Error Resume Next Command1.Enabled = False '// Launch the app and store its window handle lngInst = Shell("C:\MyApp.Exe", SW_MINIMIZE) '// Start the timer intStart = Timer blnTimeOut = False Do While GetModuleUsage(lngInst) > 0 DoEvents If Abs(Timer - intStart) > 30 Then blnTimeOut = True Exit Do End If Loop If blnTimeOut Then MsgBox "Timed out, 30 seconds passed!", 0, "Warning" Command1.Enabled = True End Sub Lanciare un programma ed attendere la sua fine |