This topic discusses how to start additional processes from a .NET application. This can be useful in scenarios where one application needs to selectively
Application #55: Use the File System
Application #73: Read From and Write to a Text File
namespace contains the
class, which contains a variety of
The sample application
The btnProcessStartInfo_Click event handler also launches Notepad, but it uses the ProcessStartInfo class to specify that it should be maximized.
Dim startInfo As New ProcessStartInfo("notepad.exe")
startInfo.WindowStyle = ProcessWindowStyle.Maximized
The btnUseVerb_Click event handler creates a text file and then creates a ProcessStartInfo object for the file.
Dim sw As New System.IO.StreamWriter("demofile_shell.txt")
sw.WriteLine("Eureka! You've printed!")
Dim startInfo As New ProcessStartInfo("demofile_shell.txt")
startInfo.Verb = "print"
This time, when we start the process we’ll maintain a reference to the returned Process instance so that we can call WaitForExit , which will force our application to block until the printing finishes.
Dim p As Process = Process.Start(startInfo)
Finally, we can delete the sample file and display a message box with the ExitCode of the process. In general, an exit code of 0 indicates a success and a nonzero number indicates some error condition.
MessageBox.Show("Printing finished with an exit code of " + _
The btnCommandLine_Click event handler uses the Arguments property of the ProcessStartInfo object to send a command-line argument to a new instance of Windows Explorer.
Dim startInfo As New ProcessStartInfo("explorer.exe")
startInfo.Arguments = "/n"
class provides a simple way to interact with other applications with very little overhead. This is especially
Visual Basic 2005 Cookbook: Solutions for VB 2005 Programmers (Cookbooks (O'Reilly))
Microsoft Visual Basic .NET Step by Step--Version 2003 (Step by Step (Microsoft))
Microsoft Visual Basic .NET Programmer's Cookbook (Pro-Developer)
Building Client/Server Applications Under VB .NET: An Example-Driven Approach