NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Process.Start (String, String)

Starts a process resource by specifying the name of an application and a set of command line arguments. Associates the process resource with a new Process component.

[Visual Basic]
Overloads Public Shared Function Start( _
   ByVal fileName As String, _
   ByVal arguments As String _
) As Process
[C#]
public static Process Start(
   string fileName,
   string arguments
);
[C++]
public: static Process* Start(
   String* fileName,
   String* arguments
);
[JScript]
public static function Start(
   fileName : String,
   arguments : String
) : Process;

Parameters

fileName
The name of an application file to run in the process.
arguments
[To be supplied.]

Return Value

A new Process component associated with the process resource, or a null reference (in Visual Basic Nothing) if no process resource is started (for example, if an existing process is reused).

Exceptions

Exception Type Condition
ArgumentException The fileName or arguments parameters are a null reference (Nothing).

Remarks

Use this overload to start a process resource by specifying its file name and command line arguments, and associate it with a new Process component. If the process is already running, no additional process resource is started. Instead, the existing process resource is reused and no new Process component is created. In such a case, instead of returning a new Process component, the call to Start returns a null reference (Nothing) to the calling procedure.

This overload lets you start a process without first instantiating a Process object. It is an alternate for the explicit steps of instantiating a Process object, setting the FileName and Arguments members of the StartInfo property, and calling Start on the Process.

The behavior of a process started by specifying its fileName and arguments is similar to typing the fileName and arguments into the Run dialog box of the Windows Start menu. Therefore, the fileName does not have to be an executable. It can be any file type whose extension has been associated with an application installed on the system, for example ".txt" if you have associated text files with an editor like Notepad, or ".doc" if you have .doc files associated with a word processing tool like Microsoft Word. Similarly, in the same way that the Run dialog box can accept an executable name with or without the extension, the extension is optional as well in the fileName parameter. For example, you can set the fileName to either "Notepad.exe" or "Notepad". If fileName represents an executable, arguments

may represent, for example, a file to act upon, such as the text file in Notepad

myfile.

This overload of the Start method is a static (in Visual Basic Shared) member. You do not need to create an instance of the Process component before you call the method. You can call Start on the Process class itself. The process resource is automatically associated with the new Process component returned by the call to the Start method.

Unlike the other overloads, the parameterless overload of Start is not a static (Shared) member. Use the parameterless overload when you have already created a Process instance, specified start information including the file name, and want to start a process resource and associate it with the existing Process. Use one of the static (Shared) overloads when you want to create a new Process component rather than start a process on an existing component. Both this overload and the parameterless overload allow you to specify the file name of the process resource and command line arguments to pass into the call to start the process.

Whenever you use Start to start a process, you must be sure to close it or you risk losing system resources. You close processes using CloseMainWindow or Kill. CloseMainWindow is used to close processes that contain a graphical interface, while Kill must be used for non-graphical applications that do not have a message pump to handle a windows Close request.

Note   Currently, all processes started using a Process component open in a command window. They contain a message loop and you can attempt to close them using CloseMainWindow. This will change in a future release. Depending on how the non-graphical interface process is coded, CloseMainWindow could fail and Kill could be necessary in order to stop the process.

Example

The following example demonstrates starting Internet Explorer as a process from within your application. It passes in the URL

See Also

Process Class | Process Members | System.Diagnostics Namespace | Process.Start Overload List