Is there anyway that I can call a external application... say... notepad... and have the calling app stop execution until notepad has finished executing???
Printable View
Is there anyway that I can call a external application... say... notepad... and have the calling app stop execution until notepad has finished executing???
i don't know if this would work but...
That would not run the application or whatever you wanted to do until the Notepad window is present, and i don't think that is the default title of notepad, check it for yourself before you use it.Code:If FindWindow("Notepad - untitled",vbnullstring) <> 0 then
'whatever you want to do here
End If
Rh0ads: FindWindow API function is used like: FindWindow(Class, Caption) ( -- FindWindow("SciCalc", "Calculator") )
But you don't need that API function for this.
Try this instead:
VB Code:
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 Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As _ Long) Const STILL_ACTIVE = &H103 Const PROCESS_QUERY_INFORMATION = &H400 'JobtoDo - Program to run Sub ShellWait(ByVal JobToDo As String) Dim hProcess As Long Dim RetVal As Long 'The next line launches JobToDo as icon, 'captures process ID hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1)) Do 'Get the status of the process GetExitCodeProcess hProcess, RetVal 'Sleep command recommended as well as DoEvents DoEvents: Sleep 100 'Loop while the process is active Loop While RetVal = STILL_ACTIVE Msgbox "App has been unloaded! Ready to continue..." End Sub [b][u]Usage[/u][/b] Private Sub Command1_Click() Call ShellWait("C:\App\App.exe") End Sub