You can use the Process component to start processes on your system by calling the Start method. Before you call Start, you must specify the file name of the process to start by setting the FileName property to either the fully qualified path to the target process, or in the case of qualified Windows applications such as Notepad, simply the process name.
You can set the FileName property at design time, using the Properties window, or at run time by using a value of the StartInfo enumeration. If you set the file name at run time, you can do one of the following:
- Set the appropriate value of the StartInfo enumeration and then call Start, or
- Call the static form of the Start method and specify FileName as a parameter. Use this approach if you do not need to set any other starting parameters; you cannot set any other opening arguments in this method.
To start a process at run time using the StartInfo properties
- Set the starting information by exposed by the StartInfo property.
- Call the Start method of the Process component.
The following example shows how to open Notepad in a maximized window.
' Visual Basic Dim myProcess as New Process() myProcess.StartInfo.FileName = "Notepad.exe" myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized myProcess.Start() // C# Process myProcess = new Process(); myProcess.StartInfo.FileName = "Notepad"; myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; myProcess.Start();
To start a process at run time by passing the FileName parameter
- Call the Start method, entering the FileName parameter as a string expression.
' Visual Basic myProcess.Start("Notepad.exe") // C# Process myProcess = Process.Start("Notepad");