VB6 let you launch external programs using the Shell command and you could control the launched program's window style with the windowstyle parameter. To wait for the external program to terminate you could use the WaitForSingleObject API view the VB6 sample. NET you can use the Microsoft. Compatibility namespace and still call the Shell command but there's a better way.
Diagnostics namespace has a Process class you can launch external programs waitforexit. You pass in the name of an executable file or a filename with an extension associated with an executable application.
Start method takes a ProcessStartInfo parameter that let's you set process initialization values such as the WindowStyle. You can also do all of waitforexit through the IDE by dragging a Process component unto your form waitforexit the Components area of the Toolbar. To wait for a launched process to end, call the Process. Your application will stop process until the launched process exits.
However, this will cause your application to stop responding to system events, such as the Paint event. You can start a process and get its output without a visible window. The Process class can raise process Exited event when a process waitforexit. You must set the Process.
EnableRaisingEvents property True and create an event handler. You may need to send input directly to a launched process and send the output directly back to your program. For programs that use StdIn, StdOutand StdErrsuch as console applications, you can override the defaults and provide a StreamWriter to write input and StreamReaders to read the StdOut and StdErr outputs. UseShellExecute property False before starting the process.
Also, you must either specify the full path to the file, or the file location must be in the environment path string or in one of the places Windows searches for files. For programs that don't use StdIn, you can use the SendKeys method to input keystrokes. If you use this code, please mention "www. Launch and monitor external programs from. NET VB6 let you launch external programs using the Shell command and you could control the launched program's window style with the windowstyle parameter.
Launching an external program. ProcessName An overloaded Process. Dim psInfo As New System. Start psInfo Or, Dim myProcess As System. Start You can also do all of this through the IDE by dragging a Process component unto your form from the Components area of the Toolbar. Start a process and wait until it exits. ExitCode ' ' Close the process to free resources. Process Start an invisible process.
System ' ' Createe the command line. Waitforexit ' ' Kill the process process it doesn't finish in one minute. WaitForExit If Not myProcess. Kill End If ' ' Show the results. Close Determine when a process exits. Start ' ' Event handler. Close End Sub Note, if the launched process hangs your application will too.
Process If Not myProcess. Kill End If MessageBox. Show s For programs that don't use StdIn, you can use the SendKeys method to input keystrokes. Start ' ' Wait until the program is ready for input. WaitForInputIdle If myProcess.