ProblemYou need to start up a separate application, based on either the path to the executable program file, a document with a registered file extension, or a valid URL for a web page or other resource. SolutionUse the System.Diagnostics.Process.Start() method to initiate applications external to your own application. DiscussionThe Start() method returns an object of type System.Diagnostics.Process that encapsulates the newly started application. Process.Start() works with three types of targets:
The arguments passed to Process.Start() are similar to those you would enter in the Windows Start Run menu command prompt, or in the Windows Command Prompt using the Start command. The Process object returned by Process.Start() includes several properties and methods that let you monitor and control (somewhat) the new process. To force the new process to exit, use the Process object's Kill() method. Visual Basic also includes another command from its pre-.NET days that starts up external applications. The Shell() function accepts two arguments: the command and the window style. The command is the executable filename of the program to run, with any command-line arguments included. The second argument uses the members of the Microsoft.VisualBasic.AppWinStyle enumeration to indicate whether the new program's main window should start as maximized, minimized, or normal, and whether it should immediately receive the input focus. Here are the choices:
For example, to start up Notepad with a specific file open, use this command: Shell("Notepad.exe C:\DataFile.txt", _ AppWinStyle.NormalFocus) You can use only executable programs with Shell(). It does not accept URLs or files with registered extensions. See AlsoRecipe 14.5 shows how to wait for the newly started process to complete before continuing with the main program. |