.NET Framework Class Library
Process..::.Start Method (String, String, SecureString, String)

Starts a process resource by specifying the name of an application, a user name, a password, and a domain and associates the resource with a new Process component.

Namespace:  System.Diagnostics
Assembly:  System (in System.dll)
Syntax

Visual Basic (Declaration)
Public Shared Function Start ( _
    fileName As String, _
    userName As String, _
    password As SecureString, _
    domain As String _
) As Process
Visual Basic (Usage)
Dim fileName As String
Dim userName As String
Dim password As SecureString
Dim domain As String
Dim returnValue As Process

returnValue = Process.Start(fileName, _
    userName, password, domain)
C#
public static Process Start(
    string fileName,
    string userName,
    SecureString password,
    string domain
)
Visual C++
public:
static Process^ Start(
    String^ fileName, 
    String^ userName, 
    SecureString^ password, 
    String^ domain
)
JScript
public static function Start(
    fileName : String, 
    userName : String, 
    password : SecureString, 
    domain : String
) : Process

Parameters

fileName
Type: System..::.String
The name of an application file to run in the process.
userName
Type: System..::.String
The user name to use when starting the process.
password
Type: System.Security..::.SecureString
A SecureString that contains the password to use when starting the process.
domain
Type: System..::.String
The domain to use when starting the process.

Return Value

Type: System.Diagnostics..::.Process
A new Process component that is associated with the process resource, or nullNothingnullptra null reference (Nothing in Visual Basic) if no process resource is started (for example, if an existing process is reused).
Exceptions

ExceptionCondition
InvalidOperationException

No file name was specified.

Win32Exception

fileName is not an executable (.exe) file.

Win32Exception

There was an error in opening the associated file.

ObjectDisposedException

The process object has already been disposed.

Remarks

Use this overload to create a new process and its primary thread by specifying its file name, user name, password, and domain. The new process then runs the specified executable file in the security context of the specified credentials (user, domain, and password).

NoteNote:

When the executable file is located on a remote drive, you must identify the network share by using a uniform resource identifier (URI), not a linked drive letter.

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, Start returns nullNothingnullptra null reference (Nothing in Visual Basic) to the calling procedure.

This overload lets you start a process without first creating a new Process instance. The overload is an alternative to the explicit steps of creating a new Process instance, setting the FileName, UserName, Password, and Domain properties of the StartInfo property, and calling Start for the Process instance.

Similarly, in the same way that the Run dialog box can accept an executable file name with or without the .exe extension, the .exe extension is optional in the fileName parameter. For example, you can set the fileName parameter to either "Notepad.exe" or "Notepad". If the fileName parameter represents an executable file, the arguments parameter might represent a file to act upon, such as the text file in Notepad.exe myfile.txt.

NoteNote:

The file name must represent an executable file in the Start overloads that have userName, password, and domain parameters.

Examples

The following code example shows the use of this overload to start an executable file and also demonstrates the throwing of a Win32Exception when an attempt is made to start an application associated with a nonexecutable file.

Visual Basic
' This sample requires a text.txt file and a HelloWorld.exe file in the 
' My Documents folder to successfully execute.
Imports System
Imports System.Diagnostics
Imports System.Security
Imports System.ComponentModel

Class Program

    Shared Sub Main(ByVal args() As String) 
        Console.WriteLine("Enter your domain.")
        Dim domain As String = Console.ReadLine()
        Console.WriteLine("Enter you user name.")
        Dim uname As String = Console.ReadLine()
        Console.WriteLine("Enter your password (Caution, password won't be hidden).")
        Dim password As New SecureString()
        Dim c As Char
        For Each c In  Console.ReadLine()
            password.AppendChar(c)
        Next c
        Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\"
        Process.Start(path + "HelloWorld.exe", uname, password, domain)
        Try
            ' The following call to Start succeeds.
            Process.Start(path + "Text.txt")
            ' Attempting to start in a shell using this Start overload fails.
            ' The following call to Start results in the following error:
            ' The specified executable is not a valid Win32 application.
            Process.Start(path + "Text.txt", uname, password, domain)
        Catch ex As Win32Exception
            Console.WriteLine(ex.Message)
        End Try

    End Sub 'Main
End Class 'Program
C#
// This sample requires a text.txt file and a HelloWorld.exe file in the 
// My Documents folder to successfully execute.
using System;
using System.Diagnostics;
using System.Security;
using System.ComponentModel;

namespace StartDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter your domain.");
            string domain = Console.ReadLine();
            Console.WriteLine("Enter you user name.");
            string uname = Console.ReadLine();
            Console.WriteLine("Enter your password (Caution, password won't be hidden).");
            SecureString password = new SecureString();
            foreach (char c in Console.ReadLine())
                password.AppendChar(c);
            string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\";
            Process.Start(path + "HelloWorld.exe", uname, password, domain);
            try
            {
                // The following call to Start succeeds.
                Process.Start(path + "Text.txt");
                // Attempting to start in a shell using this Start overload fails.
                // The following call to Start results in the following error:
                // The specified executable is not a valid Win32 application.
                Process.Start(path + "Text.txt", uname, password, domain);
            }
            catch (Win32Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
     }
}
.NET Framework Security

  • LinkDemand 

    for full trust for the immediate caller. This member cannot be used by partially trusted code.

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Community Content

Thomas Lee
domain Parameter of Start not honored
It appears from testing the sampe code that the "domain" argument of the "Start" method is ignored always.

Running the sample code exactly and changing the domain value does not affect the execution. Only user and password can affect the outcome.
Tags : contentbug

Thomas Lee
WaitForExit Help

Refer to my blog for very helpful advice on WaitForExit Process examples.

Jeff Fischer


Page view tracker