Process.Start メソッド

定義

プロセス リソースを起動し、Process コンポーネントに関連付けます。

オーバーロード

Start(String, String, String, SecureString, String)

アプリケーションの名前、コマンド ライン引数のセット、ユーザー名、パスワード、およびドメインを指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

Start(String, String, SecureString, String)

アプリケーションの名前、ユーザー名、パスワード、ドメインを指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

Start(String, String)

アプリケーションの名前とコマンド ライン引数のセットを指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

Start(String)

文書またはアプリケーション ファイルの名前を指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

Start(ProcessStartInfo)

プロセス起動情報 (起動するプロセスのファイル名など) が格納されているパラメーターで指定されたプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

Start()

この Process コンポーネントの StartInfo プロパティで指定されたプロセス リソースを起動 (または再利用) し、コンポーネントに関連付けます。

Start(String, IEnumerable<String>)

アプリケーションの名前とコマンド ライン引数のセットを指定してプロセス リソースを起動します。

Start(String, String, String, SecureString, String)

重要

この API は CLS 準拠ではありません。

アプリケーションの名前、コマンド ライン引数のセット、ユーザー名、パスワード、およびドメインを指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

public:
 static System::Diagnostics::Process ^ Start(System::String ^ fileName, System::String ^ arguments, System::String ^ userName, System::Security::SecureString ^ password, System::String ^ domain);
[System.CLSCompliant(false)]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Diagnostics.Process? Start (string fileName, string arguments, string userName, System.Security.SecureString password, string domain);
[System.CLSCompliant(false)]
public static System.Diagnostics.Process Start (string fileName, string arguments, string userName, System.Security.SecureString password, string domain);
public static System.Diagnostics.Process Start (string fileName, string arguments, string userName, System.Security.SecureString password, string domain);
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Start : string * string * string * System.Security.SecureString * string -> System.Diagnostics.Process
[<System.CLSCompliant(false)>]
static member Start : string * string * string * System.Security.SecureString * string -> System.Diagnostics.Process
static member Start : string * string * string * System.Security.SecureString * string -> System.Diagnostics.Process
Public Shared Function Start (fileName As String, arguments As String, userName As String, password As SecureString, domain As String) As Process

パラメーター

fileName
String

プロセスで実行するアプリケーション ファイルの名前。

arguments
String

プロセスを起動するときに渡すコマンド ライン引数。

userName
String

プロセスの開始時に使用するユーザー名。

password
SecureString

プロセスを開始するときに使用するパスワードを含む SecureString

domain
String

プロセスの開始時に使用するドメイン。

戻り値

プロセス リソースに関連付けられている新しい Process。プロセス リソースが起動されていない場合は null。 同じプロセスのインスタンスが既に実行されているときに起動された新しいプロセスは、他のインスタンスから独立します。 また、Start では、HasExited プロパティが既に true に設定されている null 以外の Process が返される場合があります。 その場合、起動されたプロセス自体の既存のインスタンスがアクティブ化され、その後に終了されることがあります。

属性

例外

ファイル名が指定されませんでした。

関連付けられているファイルを開いているときにエラーが発生しました。

または

fileName で指定したファイルが見つかりませんでした。

または

引数の長さと関連ファイルへの完全パスの長さの合計が、2080 文字を超えています。 この例外に関連付けられているエラー メッセージは、"システム呼び出しに渡されるデータ領域が小さすぎます" または "アクセスが拒否されました" のいずれかです。

プロセス オブジェクトは既には破棄されています。

このメンバーは Linux または macOS (.NET Core のみ) ではサポートされていません。

注釈

このオーバーロードを使用して、ファイル名、コマンドライン引数、ユーザー名、パスワード、ドメインを指定して、新しいプロセスとそのプライマリ スレッドを作成します。 その後、新しいプロセスは、指定された資格情報 (ユーザー、ドメイン、パスワード) のセキュリティ コンテキストで、指定された実行可能ファイルを実行します。

注意

実行可能ファイルがリモート ドライブ上にある場合は、リンクされたドライブ文字ではなく、UNIFORM Resource Identifier (URI) を使用してネットワーク共有を識別する必要があります。

注意

開始する実行可能ファイルのアドレスが URL の場合、プロセスは開始されず、 null 返されます。

このオーバーロードを使用すると、最初に新しい Process インスタンスを作成せずにプロセスを開始できます。 オーバーロードは、新しいProcessインスタンスを作成し、プロパティの 、UserNameArguments、、Passwordおよび プロパティをFileName設定しDomain、インスタンスを呼び出すStartProcess明示的な手順のStartInfo代わりに使用します。

同様に、[ 実行 ] ダイアログ ボックスで、.exe拡張子の有無にかかわらず実行可能ファイル名を受け入れるのと同じ方法で、.exe拡張子はパラメーターで fileName 省略可能です。 たとえば、 パラメーターを fileName "Notepad.exe" または "メモ帳" に設定できます。 パラメーターが fileName 実行可能ファイルを表す場合、 arguments パラメーターは、 内のテキスト ファイルなど、処理するファイル Notepad.exe myfile.txtを表している可能性があります。

注意

ファイル名は、および パラメーターを持つuserNamepasswordオーバーロード内のStart実行可能ファイルをdomain表す必要があります。

を使用 Start してプロセスを開始するたびに、プロセスを閉じる必要があるか、システム リソースが失われるリスクがあります。 または Killを使用してプロセスをCloseMainWindow閉じます。 プロセスが既に閉じているかどうかを確認する場合は、そのプロパティを HasExited 使用します。

適用対象

Start(String, String, SecureString, String)

重要

この API は CLS 準拠ではありません。

アプリケーションの名前、ユーザー名、パスワード、ドメインを指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

public:
 static System::Diagnostics::Process ^ Start(System::String ^ fileName, System::String ^ userName, System::Security::SecureString ^ password, System::String ^ domain);
[System.CLSCompliant(false)]
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Diagnostics.Process? Start (string fileName, string userName, System.Security.SecureString password, string domain);
[System.CLSCompliant(false)]
public static System.Diagnostics.Process Start (string fileName, string userName, System.Security.SecureString password, string domain);
public static System.Diagnostics.Process Start (string fileName, string userName, System.Security.SecureString password, string domain);
[<System.CLSCompliant(false)>]
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Start : string * string * System.Security.SecureString * string -> System.Diagnostics.Process
[<System.CLSCompliant(false)>]
static member Start : string * string * System.Security.SecureString * string -> System.Diagnostics.Process
static member Start : string * string * System.Security.SecureString * string -> System.Diagnostics.Process
Public Shared Function Start (fileName As String, userName As String, password As SecureString, domain As String) As Process

パラメーター

fileName
String

プロセスで実行するアプリケーション ファイルの名前。

userName
String

プロセスの開始時に使用するユーザー名。

password
SecureString

プロセスを開始するときに使用するパスワードを含む SecureString

domain
String

プロセスの開始時に使用するドメイン。

戻り値

プロセス リソースに関連付けられている新しい Process。プロセス リソースが起動されていない場合は null。 同じプロセスのインスタンスが既に実行されているときに起動された新しいプロセスは、他のインスタンスから独立します。 また、Start では、HasExited プロパティが既に true に設定されている null 以外の Process が返される場合があります。 その場合、起動されたプロセス自体の既存のインスタンスがアクティブ化され、その後に終了されることがあります。

属性

例外

ファイル名が指定されませんでした。

関連付けられているファイルを開いているときにエラーが発生しました。

または

fileName で指定したファイルが見つかりませんでした。

プロセス オブジェクトは既には破棄されています。

このメンバーは Linux または macOS (.NET Core のみ) ではサポートされていません。

次のコード例では、このオーバーロードを使用して実行可能ファイルを起動し、実行不可能なファイルに関連付けられているアプリケーションを起動しようとした場合の Win32Exception のスローも示しています。

// NOTE: This example requires a text.txt file file in your Documents folder
using System;
using System.Diagnostics;
using System.Security;
using System.ComponentModel;

class Example
{
    static void Main()
    {
        Console.Write("Enter your domain: ");
        string domain = Console.ReadLine();
        Console.Write("Enter you user name: ");
        string uname = Console.ReadLine();
        Console.Write("Enter your password: ");
        SecureString password = new SecureString();
        ConsoleKeyInfo key;
        do
        {
            key = Console.ReadKey(true);

            // Ignore any key out of range.
            if (((int)key.Key) >= 33 && ((int)key.Key <= 90) && key.Key != ConsoleKey.Enter)
            {
                // Append the character to the password.
                password.AppendChar(key.KeyChar);
                Console.Write("*");
            }
            // Exit if Enter key is pressed.
        } while (key.Key != ConsoleKey.Enter);
        Console.WriteLine();

        try
        {
            Console.WriteLine("\nTrying to launch NotePad using your login information...");
            Process.Start("notepad.exe", uname, password, domain);
        }
        catch (Win32Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\";

        try
        {
            // The following call to Start succeeds if test.txt exists.
            Console.WriteLine("\nTrying to launch 'text.txt'...");
            Process.Start(path + "text.txt");
        }
        catch (Win32Exception ex)
        {
            Console.WriteLine(ex.Message);
        }

        try
        {
            // Attempting to start in a shell using this Start overload fails. This causes
            // the following exception, which is picked up in the catch block below:
            // The specified executable is not a valid application for this OS platform.
            Console.WriteLine("\nTrying to launch 'text.txt' with your login information...");
            Process.Start(path + "text.txt", uname, password, domain);
        }
        catch (Win32Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        finally
        {
            password.Dispose();
        }
    }
}
' This sample requires a text.txt file file in your documents folder.
' You'll also need to set the startup object in the project to Sub Main.
Imports System.Diagnostics
Imports System.Security
Imports System.ComponentModel

Module Program
    Sub Main()
        Console.Write("Enter your domain: ")
        Dim domain As String = Console.ReadLine()
        Console.Write("Enter you user name: ")
        Dim uname As String = Console.ReadLine()
        Console.Write("Enter your password: ")
        Dim password As New SecureString()
        Dim key As ConsoleKeyInfo
        Do
            key = Console.ReadKey(True)

            ' Ignore any key out of range.
            If key.Key >= 33 AndAlso key.Key <= 90 AndAlso key.Key <> ConsoleKey.Enter Then
                ' Append the character to the password.
                password.AppendChar(key.KeyChar)
                Console.Write("*")
            End If
            ' Exit if Enter key is pressed.
        Loop While key.Key <> ConsoleKey.Enter
        Console.WriteLine()

        Try
            Console.WriteLine(vbCrLf + "Trying to launch NotePad using your login information...")
            Process.Start("notepad.exe", uname, password, domain)
        Catch ex As Win32Exception
            Console.WriteLine(ex.Message)
        End Try

        Dim path As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\"

        Try
            ' The following call to Start succeeds if test.txt exists.
            Console.WriteLine(vbCrLf + "Trying to launch 'text.txt'...")
            Process.Start(path + "Text.txt")
        Catch ex As Win32Exception
            Console.WriteLine(ex.Message)
        End Try

        Try
            ' Attempting to start in a shell using this Start overload fails. This causes
            ' the following exception, which is picked up in the catch block below:
            ' The specified executable is not a valid application for this OS platform.
            Console.WriteLine(vbCrLf + "Trying to launch 'text.txt' with your login information...")
            Process.Start(path + "Text.txt", uname, password, domain)
        Catch ex As Win32Exception
            Console.WriteLine(ex.Message)
        Finally
            password.Dispose()
        End Try
    End Sub
End Module

注釈

このオーバーロードを使用して、ファイル名、ユーザー名、パスワード、ドメインを指定して、新しいプロセスとそのプライマリ スレッドを作成します。 その後、新しいプロセスは、指定された資格情報 (ユーザー、ドメイン、パスワード) のセキュリティ コンテキストで、指定された実行可能ファイルを実行します。

注意

実行可能ファイルがリモート ドライブ上にある場合は、リンクされたドライブ文字ではなく、UNIFORM Resource Identifier (URI) を使用してネットワーク共有を識別する必要があります。

注意

開始する実行可能ファイルのアドレスが URL の場合、プロセスは開始されず、 null 返されます。

このオーバーロードを使用すると、最初に新しい Process インスタンスを作成せずにプロセスを開始できます。 オーバーロードは、新しいProcessインスタンスを作成し、プロパティの 、UserNamePassword、および プロパティStartInfoを設定しDomain、インスタンスをFileName呼び出すStartProcess明示的な手順の代わりに使用します。

同様に、[ 実行 ] ダイアログ ボックスで、.exe拡張子の有無にかかわらず実行可能ファイル名を受け入れるのと同じ方法で、.exe拡張子はパラメーターで fileName 省略可能です。 たとえば、 パラメーターを fileName "Notepad.exe" または "メモ帳" に設定できます。 パラメーターが fileName 実行可能ファイルを表す場合、 arguments パラメーターは、 内のテキスト ファイルなど、処理するファイル Notepad.exe myfile.txtを表している可能性があります。

注意

ファイル名は、および パラメーターを持つuserNamepasswordオーバーロード内のStart実行可能ファイルをdomain表す必要があります。

を使用 Start してプロセスを開始するたびに、プロセスを閉じる必要があるか、システム リソースが失われるリスクがあります。 または Killを使用してプロセスをCloseMainWindow閉じます。 プロセスが既に閉じているかどうかを確認する場合は、そのプロパティを HasExited 使用します。

適用対象

Start(String, String)

アプリケーションの名前とコマンド ライン引数のセットを指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

public:
 static System::Diagnostics::Process ^ Start(System::String ^ fileName, System::String ^ arguments);
public static System.Diagnostics.Process Start (string fileName, string arguments);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process Start (string fileName, string arguments);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
public static System.Diagnostics.Process Start (string fileName, string arguments);
static member Start : string * string -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member Start : string * string -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
static member Start : string * string -> System.Diagnostics.Process
Public Shared Function Start (fileName As String, arguments As String) As Process

パラメーター

fileName
String

プロセスで実行するアプリケーション ファイルの名前。

arguments
String

プロセスを起動するときに渡すコマンド ライン引数。

戻り値

プロセス リソースに関連付けられている新しい Process。プロセス リソースが起動されていない場合は null。 同じプロセスのインスタンスが既に実行されているときに起動された新しいプロセスは、他のインスタンスから独立します。 また、Start では、HasExited プロパティが既に true に設定されている null 以外の Process が返される場合があります。 その場合、起動されたプロセス自体の既存のインスタンスがアクティブ化され、その後に終了されることがあります。

属性

例外

fileName パラメーターまたは arguments パラメーターが null です。

関連付けられているファイルを開いているときにエラーが発生しました。

または

fileName で指定したファイルが見つかりませんでした。

または

引数の長さとプロセスへの完全パスの長さの合計が、2080 文字を超えています。 この例外に関連付けられているエラー メッセージは、"システム呼び出しに渡されるデータ領域が小さすぎます" または "アクセスが拒否されました" のいずれかです。

プロセス オブジェクトは既には破棄されています。

PATH 環境変数に、引用符を含む文字列があります。

次の例では、最初に Internet Explorer のインスタンスを生成し、ブラウザーに [お気に入り] フォルダーの内容を表示します。 次に、Internet Explorer の他のインスタンスを起動し、特定のページまたはサイトを表示します。 最後に、特定のサイトに移動中にウィンドウが最小化された状態で Internet Explorer を起動します。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

// Opens the Internet Explorer application.
void OpenApplication(String^ myFavoritesPath)
{
    // Start Internet Explorer. Defaults to the home page.
    Process::Start("IExplore.exe");

    // Display the contents of the favorites folder in the browser.
    Process::Start(myFavoritesPath);
}

// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
    // URLs are not considered documents. They can only be opened
    // by passing them as arguments.
    Process::Start("IExplore.exe", "www.northwindtraders.com");

    // Start a Web page using a browser associated with .html and .asp files.
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.htm");
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
    ProcessStartInfo^ startInfo = gcnew ProcessStartInfo("IExplore.exe");
    startInfo->WindowStyle = ProcessWindowStyle::Minimized;
    Process::Start(startInfo);
    startInfo->Arguments = "www.northwindtraders.com";
    Process::Start(startInfo);
}

int main()
{
    // Get the path that stores favorite links.
    String^ myFavoritesPath = Environment::GetFolderPath(Environment::SpecialFolder::Favorites);
    OpenApplication(myFavoritesPath);
    OpenWithArguments();
    OpenWithStartInfo();
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        // Opens the Internet Explorer application.
        void OpenApplication(string myFavoritesPath)
        {
            // Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe");

            // Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath);
        }

        // Opens urls and .html documents using Internet Explorer.
        void OpenWithArguments()
        {
            // url's are not considered documents. They can only be opened
            // by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com");

            // Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
        }

        // Uses the ProcessStartInfo class to start new processes,
        // both in a minimized mode.
        void OpenWithStartInfo()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;

            Process.Start(startInfo);

            startInfo.Arguments = "www.northwindtraders.com";

            Process.Start(startInfo);
        }

        static void Main()
        {
            // Get the path that stores favorite links.
            string myFavoritesPath =
                Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            MyProcess myProcess = new MyProcess();

            myProcess.OpenApplication(myFavoritesPath);
            myProcess.OpenWithArguments();
            myProcess.OpenWithStartInfo();
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        ' Opens the Internet Explorer application.
        Public Sub OpenApplication(myFavoritesPath As String)
            ' Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe")

            ' Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath)
        End Sub

        ' Opens URLs and .html documents using Internet Explorer.
        Sub OpenWithArguments()
            ' URLs are not considered documents. They can only be opened
            ' by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com")

            ' Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
            Process.Start("IExplore.exe", "C:\myPath\myFile.asp")
        End Sub

        ' Uses the ProcessStartInfo class to start new processes,
        ' both in a minimized mode.
        Sub OpenWithStartInfo()
            Dim startInfo As New ProcessStartInfo("IExplore.exe")
            startInfo.WindowStyle = ProcessWindowStyle.Minimized

            Process.Start(startInfo)

            startInfo.Arguments = "www.northwindtraders.com"

            Process.Start(startInfo)
        End Sub

        Shared Sub Main()
            ' Get the path that stores favorite links.
            Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)

            Dim myProcess As New MyProcess()

            myProcess.OpenApplication(myFavoritesPath)
            myProcess.OpenWithArguments()
            myProcess.OpenWithStartInfo()
        End Sub
    End Class
End Namespace 'MyProcessSample

注釈

このオーバーロードを使用して、ファイル名とコマンド ライン引数を指定してプロセス リソースを開始します。 オーバーロードは、リソースを新 Process しいオブジェクトに関連付けます。

注意

開始する実行可能ファイルのアドレスが URL の場合、プロセスは開始されず、 null 返されます。

このオーバーロードを使用すると、最初に新しい Process インスタンスを作成せずにプロセスを開始できます。 オーバーロードは、新しいProcessインスタンスを作成し、 プロパティの メンバーと Arguments メンバーStartInfoを設定FileNameし、 インスタンスを呼び出すStartProcess明示的な手順の代わりに使用します。

ファイル名と引数を指定してプロセスを開始することは、Windows Start メニューのダイアログ ボックスにファイル名とコマンド ライン引数をRun入力するのと似ています。 したがって、ファイル名は実行可能ファイルを表す必要はありません。 拡張子がシステムにインストールされているアプリケーションに関連付けられている任意の種類のファイルにすることができます。 たとえば、テキスト ファイルをメモ帳などのエディターに関連付ける場合は、ファイル名に.txt拡張子を付けたり、word などのワープロ ツールに.docファイルを関連付けた場合は.doc Microsoftできます。 同様に、ダイアログ ボックスで、.exe拡張子の有無にかかわらず実行可能ファイル名を受け入れるのと同じ方法 Run で、.exe拡張子は パラメーターで fileName 省略可能です。 たとえば、 パラメーターを fileName "Notepad.exe" または "メモ帳" に設定できます。 パラメーターが fileName 実行可能ファイルを表す場合、 arguments パラメーターは、 内のテキスト ファイルなど、処理するファイル Notepad.exe myfile.txtを表している可能性があります。 パラメーターが fileName コマンド (.cmd) ファイルを表す場合、コマンド ウィンドウが終了するか、 arguments 完了後も残るかを指定するには、パラメーターに "/c" または "/k" 引数を含める必要があります。

他のオーバーロードとは異なり、パラメーターを持たない の Start オーバーロードはメンバーではありません static 。 インスタンスを既に作成 Process し、開始情報 (ファイル名を含む) を指定し、プロセス リソースを開始して既存 Process のインスタンスに関連付ける場合は、そのオーバーロードを使用します。 既存のコンポーネントのプロセスを static 開始するのではなく、新しい Process コンポーネントを作成する場合は、いずれかのオーバーロードを使用します。 このオーバーロードとパラメーターを持たないオーバーロードの両方で、開始するプロセス リソースのファイル名と渡すコマンド ライン引数を指定できます。

システムでパス変数を引用符で囲んで宣言している場合、その場所で見つかるプロセスを開始するときに、そのパスを完全修飾する必要があります。 そうしないと、システムはそのパスを見つけられません。 たとえば、c:\mypath がパスに含まれておらず、それを path = %path%;"c:\mypath"` のように引用符を使用して追加した場合、c:\mypath 内の任意のプロセスを開始するときに、それを完全修飾する必要があります。

注意

ASP.NET Web ページとサーバー コントロール コードは、Web サーバー上の ASP.NET ワーカー プロセスのコンテキストで実行されます。 ASP.NET Web ページまたはサーバー コントロールで メソッドを使用 Start すると、アクセス許可が制限された Web サーバー上で新しいプロセスが実行されます。 プロセスはクライアント ブラウザーと同じコンテキストで開始されず、ユーザー デスクトップにアクセスできません。

を使用 Start してプロセスを開始するたびに、プロセスを閉じる必要があるか、システム リソースが失われるリスクがあります。 または Killを使用してプロセスをCloseMainWindow閉じます。 プロセスが既に閉じているかどうかを確認する場合は、そのプロパティを HasExited 使用します。

ここでは、マネージド スレッドのアパートメントの状態に関する注意が必要です。 UseShellExecutetrueプロセス コンポーネントの StartInfo プロパティにある場合は、 メソッドの 属性[STAThread]を設定して、アプリケーションにスレッド モデルをmain()設定していることを確認します。 それ以外の場合は、マネージド スレッドをunknown状態にするか、状態にMTA置くことができます。後者は とtrue競合しますUseShellExecute。 一部のメソッドでは、アパートメントの状態が である必要はありません unknown。 状態が明示的に設定されていない場合、アプリケーションでこのようなメソッドが検出されると、既定値 MTAは に設定され、一度設定されると、アパートメントの状態を変更することはできません。 ただし、 MTA オペレーティング システム シェルがスレッドを管理しているときに例外がスローされます。

こちらもご覧ください

適用対象

Start(String)

文書またはアプリケーション ファイルの名前を指定してプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

public:
 static System::Diagnostics::Process ^ Start(System::String ^ fileName);
public static System.Diagnostics.Process Start (string fileName);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process Start (string fileName);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
public static System.Diagnostics.Process Start (string fileName);
static member Start : string -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member Start : string -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
static member Start : string -> System.Diagnostics.Process
Public Shared Function Start (fileName As String) As Process

パラメーター

fileName
String

プロセスで実行する文書またはアプリケーション ファイルの名前。

戻り値

プロセス リソースに関連付けられている新しい Process。プロセス リソースが起動されていない場合は null。 同じプロセスのインスタンスが既に実行されているときに起動された新しいプロセスは、他のインスタンスから独立します。 また、Start では、HasExited プロパティが既に true に設定されている null 以外の Process が返される場合があります。 その場合、起動されたプロセス自体の既存のインスタンスがアクティブ化され、その後に終了されることがあります。

属性

例外

関連付けられているファイルを開いているときにエラーが発生しました。

または

fileName で指定したファイルが見つかりませんでした。

プロセス オブジェクトは既には破棄されています。

PATH 環境変数に、引用符を含む文字列があります。

次の例では、最初に Internet Explorer のインスタンスを生成し、ブラウザーに [お気に入り] フォルダーの内容を表示します。 次に、Internet Explorer の他のインスタンスを起動し、特定のページまたはサイトを表示します。 最後に、特定のサイトに移動中にウィンドウが最小化された状態で Internet Explorer を起動します。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

// Opens the Internet Explorer application.
void OpenApplication(String^ myFavoritesPath)
{
    // Start Internet Explorer. Defaults to the home page.
    Process::Start("IExplore.exe");

    // Display the contents of the favorites folder in the browser.
    Process::Start(myFavoritesPath);
}

// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
    // URLs are not considered documents. They can only be opened
    // by passing them as arguments.
    Process::Start("IExplore.exe", "www.northwindtraders.com");

    // Start a Web page using a browser associated with .html and .asp files.
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.htm");
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
    ProcessStartInfo^ startInfo = gcnew ProcessStartInfo("IExplore.exe");
    startInfo->WindowStyle = ProcessWindowStyle::Minimized;
    Process::Start(startInfo);
    startInfo->Arguments = "www.northwindtraders.com";
    Process::Start(startInfo);
}

int main()
{
    // Get the path that stores favorite links.
    String^ myFavoritesPath = Environment::GetFolderPath(Environment::SpecialFolder::Favorites);
    OpenApplication(myFavoritesPath);
    OpenWithArguments();
    OpenWithStartInfo();
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        // Opens the Internet Explorer application.
        void OpenApplication(string myFavoritesPath)
        {
            // Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe");

            // Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath);
        }

        // Opens urls and .html documents using Internet Explorer.
        void OpenWithArguments()
        {
            // url's are not considered documents. They can only be opened
            // by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com");

            // Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
        }

        // Uses the ProcessStartInfo class to start new processes,
        // both in a minimized mode.
        void OpenWithStartInfo()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;

            Process.Start(startInfo);

            startInfo.Arguments = "www.northwindtraders.com";

            Process.Start(startInfo);
        }

        static void Main()
        {
            // Get the path that stores favorite links.
            string myFavoritesPath =
                Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            MyProcess myProcess = new MyProcess();

            myProcess.OpenApplication(myFavoritesPath);
            myProcess.OpenWithArguments();
            myProcess.OpenWithStartInfo();
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        ' Opens the Internet Explorer application.
        Public Sub OpenApplication(myFavoritesPath As String)
            ' Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe")

            ' Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath)
        End Sub

        ' Opens URLs and .html documents using Internet Explorer.
        Sub OpenWithArguments()
            ' URLs are not considered documents. They can only be opened
            ' by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com")

            ' Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
            Process.Start("IExplore.exe", "C:\myPath\myFile.asp")
        End Sub

        ' Uses the ProcessStartInfo class to start new processes,
        ' both in a minimized mode.
        Sub OpenWithStartInfo()
            Dim startInfo As New ProcessStartInfo("IExplore.exe")
            startInfo.WindowStyle = ProcessWindowStyle.Minimized

            Process.Start(startInfo)

            startInfo.Arguments = "www.northwindtraders.com"

            Process.Start(startInfo)
        End Sub

        Shared Sub Main()
            ' Get the path that stores favorite links.
            Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)

            Dim myProcess As New MyProcess()

            myProcess.OpenApplication(myFavoritesPath)
            myProcess.OpenWithArguments()
            myProcess.OpenWithStartInfo()
        End Sub
    End Class
End Namespace 'MyProcessSample

注釈

このオーバーロードを使用して、ファイル名を指定してプロセス リソースを開始します。 オーバーロードは、リソースを新 Process しいオブジェクトに関連付けます。

注意

開始する実行可能ファイルのアドレスが URL の場合、プロセスは開始されず、 null 返されます。

このオーバーロードを使用すると、最初に新しい Process インスタンスを作成せずにプロセスを開始できます。 オーバーロードは、新しいProcessインスタンスの作成、プロパティのメンバーの設定FileName、インスタンスの呼び出StartしのStartInfo明示的な手順に代わるProcess方法です。

ClickOnce アプリケーションを起動するには、 パラメーターを fileName 、アプリケーションを最初にインストールした場所 (Web アドレスなど) に設定します。 ハード ドライブにインストールされている場所を指定して ClickOnce アプリケーションを起動しないでください。

ファイル名を指定してプロセスを開始することは、Windows Start メニューのダイアログ ボックスに情報をRun入力するのと似ています。 したがって、ファイル名は実行可能ファイルを表す必要はありません。 拡張子がシステムにインストールされているアプリケーションに関連付けられている任意の種類のファイルにすることができます。 たとえば、テキスト ファイルをメモ帳などのエディターに関連付ける場合は、ファイル名に.txt拡張子を付けたり、word などのワープロ ツールに.docファイルを関連付けた場合は.doc Microsoftできます。 同様に、ダイアログ ボックスで、.exe拡張子の有無にかかわらず実行可能ファイル名を受け入れるのと同じ方法 Run で、.exe拡張子は パラメーターで fileName 省略可能です。 たとえば、 パラメーターを fileName "Notepad.exe" または "メモ帳" に設定できます。

このオーバーロードでは、プロセスのコマンド ライン引数は使用できません。 プロセスに 1 つ以上のコマンド ライン引数を指定する必要がある場合は、 または Process.Start(String, String) オーバーロードをProcess.Start(ProcessStartInfo)使用します。

他のオーバーロードとは異なり、パラメーターを持たない の Start オーバーロードはメンバーではありません static 。 インスタンスを既に作成 Process し、開始情報 (ファイル名を含む) を指定し、プロセス リソースを開始して既存 Process のインスタンスに関連付ける場合は、そのオーバーロードを使用します。 既存のコンポーネントのプロセスを static 開始するのではなく、新しい Process コンポーネントを作成する場合は、いずれかのオーバーロードを使用します。 このオーバーロードとパラメーターを持たないオーバーロードの両方で、開始するプロセス リソースのファイル名を指定できます。

システムでパス変数を引用符で囲んで宣言している場合、その場所で見つかるプロセスを開始するときに、そのパスを完全修飾する必要があります。 そうしないと、システムはそのパスを見つけられません。 たとえば、c:\mypath がパスに含まれておらず、それを path = %path%;"c:\mypath"` のように引用符を使用して追加した場合、c:\mypath 内の任意のプロセスを開始するときに、それを完全修飾する必要があります。

注意

ASP.NET Web ページとサーバー コントロール コードは、Web サーバー上の ASP.NET ワーカー プロセスのコンテキストで実行されます。 ASP.NET Web ページまたはサーバー コントロールで メソッドを使用 Start すると、アクセス許可が制限された Web サーバー上で新しいプロセスが実行されます。 プロセスはクライアント ブラウザーと同じコンテキストで開始されず、ユーザー デスクトップにアクセスできません。

を使用 Start してプロセスを開始するたびに、プロセスを閉じる必要があるか、システム リソースが失われるリスクがあります。 または Killを使用してプロセスをCloseMainWindow閉じます。 プロセスが既に閉じているかどうかを確認する場合は、そのプロパティを HasExited 使用します。

ここでは、マネージド スレッドのアパートメントの状態に関する注意が必要です。 UseShellExecutetrueプロセス コンポーネントの StartInfo プロパティにある場合は、 メソッドの 属性[STAThread]を設定して、アプリケーションにスレッド モデルをmain()設定していることを確認します。 それ以外の場合は、マネージド スレッドをunknown状態にするか、状態にMTA置くことができます。後者は とtrue競合しますUseShellExecute。 一部のメソッドでは、アパートメントの状態が である必要はありません unknown。 状態が明示的に設定されていない場合、アプリケーションでこのようなメソッドが検出されると、既定値 MTAは に設定され、一度設定されると、アパートメントの状態を変更することはできません。 ただし、 MTA オペレーティング システム シェルがスレッドを管理しているときに例外がスローされます。

こちらもご覧ください

適用対象

Start(ProcessStartInfo)

プロセス起動情報 (起動するプロセスのファイル名など) が格納されているパラメーターで指定されたプロセス リソースを起動し、リソースを新しい Process コンポーネントに関連付けます。

public:
 static System::Diagnostics::Process ^ Start(System::Diagnostics::ProcessStartInfo ^ startInfo);
public static System.Diagnostics.Process? Start (System.Diagnostics.ProcessStartInfo startInfo);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process? Start (System.Diagnostics.ProcessStartInfo startInfo);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
public static System.Diagnostics.Process? Start (System.Diagnostics.ProcessStartInfo startInfo);
public static System.Diagnostics.Process Start (System.Diagnostics.ProcessStartInfo startInfo);
static member Start : System.Diagnostics.ProcessStartInfo -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member Start : System.Diagnostics.ProcessStartInfo -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
static member Start : System.Diagnostics.ProcessStartInfo -> System.Diagnostics.Process
Public Shared Function Start (startInfo As ProcessStartInfo) As Process

パラメーター

startInfo
ProcessStartInfo

ファイル名やコマンド ライン引数など、プロセスの起動に使用する情報が格納されている ProcessStartInfo

戻り値

プロセス リソースに関連付けられている新しい Process。プロセス リソースが起動されていない場合は null。 同じプロセスのインスタンスが既に実行されているときに起動された新しいプロセスは、他のインスタンスから独立します。 また、Start では、HasExited プロパティが既に true に設定されている null 以外の Process が返される場合があります。 その場合、起動されたプロセス自体の既存のインスタンスがアクティブ化され、その後に終了されることがあります。

属性

例外

startInfo パラメーターの FileName プロパティにファイル名が指定されませんでした。

または

startInfo パラメーターの UseShellExecute プロパティは true であり、RedirectStandardInputRedirectStandardOutput、または RedirectStandardError プロパティも true です。

または

startInfo パラメーターの UseShellExecute プロパティは true であり、UserName プロパティは null でも空でもないか、または Password プロパティは null ではありません。

startInfo パラメーターが null です。

プロセス オブジェクトは既には破棄されています。

関連付けられているファイルを開いているときにエラーが発生しました。

または

startInfo パラメーターの FileName プロパティに指定されたファイルを見つけることができませんでした。

または

引数の長さとプロセスへの完全パスの長さの合計が、2080 文字を超えています。 この例外に関連付けられているエラー メッセージは、"システム呼び出しに渡されるデータ領域が小さすぎます" または "アクセスが拒否されました" のいずれかです。

メソッドはシェルがサポートされていない Nano Server (.NET Core のみ) などのオペレーティング システムではサポートされていません。

次の例では、最初に Internet Explorer のインスタンスを生成し、ブラウザーに [お気に入り] フォルダーの内容を表示します。 次に、Internet Explorer の他のインスタンスを起動し、特定のページまたはサイトを表示します。 最後に、特定のサイトに移動中にウィンドウが最小化された状態で Internet Explorer を起動します。

このメソッドのその他の使用例については、 クラスの個々のプロパティを ProcessStartInfo 参照してください。

#using <System.dll>

using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

// Opens the Internet Explorer application.
void OpenApplication(String^ myFavoritesPath)
{
    // Start Internet Explorer. Defaults to the home page.
    Process::Start("IExplore.exe");

    // Display the contents of the favorites folder in the browser.
    Process::Start(myFavoritesPath);
}

// Opens urls and .html documents using Internet Explorer.
void OpenWithArguments()
{
    // URLs are not considered documents. They can only be opened
    // by passing them as arguments.
    Process::Start("IExplore.exe", "www.northwindtraders.com");

    // Start a Web page using a browser associated with .html and .asp files.
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.htm");
    Process::Start("IExplore.exe", "C:\\myPath\\myFile.asp");
}

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
void OpenWithStartInfo()
{
    ProcessStartInfo^ startInfo = gcnew ProcessStartInfo("IExplore.exe");
    startInfo->WindowStyle = ProcessWindowStyle::Minimized;
    Process::Start(startInfo);
    startInfo->Arguments = "www.northwindtraders.com";
    Process::Start(startInfo);
}

int main()
{
    // Get the path that stores favorite links.
    String^ myFavoritesPath = Environment::GetFolderPath(Environment::SpecialFolder::Favorites);
    OpenApplication(myFavoritesPath);
    OpenWithArguments();
    OpenWithStartInfo();
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        // Opens the Internet Explorer application.
        void OpenApplication(string myFavoritesPath)
        {
            // Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe");

            // Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath);
        }

        // Opens urls and .html documents using Internet Explorer.
        void OpenWithArguments()
        {
            // url's are not considered documents. They can only be opened
            // by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com");

            // Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.htm");
            Process.Start("IExplore.exe", "C:\\myPath\\myFile.asp");
        }

        // Uses the ProcessStartInfo class to start new processes,
        // both in a minimized mode.
        void OpenWithStartInfo()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo("IExplore.exe");
            startInfo.WindowStyle = ProcessWindowStyle.Minimized;

            Process.Start(startInfo);

            startInfo.Arguments = "www.northwindtraders.com";

            Process.Start(startInfo);
        }

        static void Main()
        {
            // Get the path that stores favorite links.
            string myFavoritesPath =
                Environment.GetFolderPath(Environment.SpecialFolder.Favorites);

            MyProcess myProcess = new MyProcess();

            myProcess.OpenApplication(myFavoritesPath);
            myProcess.OpenWithArguments();
            myProcess.OpenWithStartInfo();
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        ' Opens the Internet Explorer application.
        Public Sub OpenApplication(myFavoritesPath As String)
            ' Start Internet Explorer. Defaults to the home page.
            Process.Start("IExplore.exe")

            ' Display the contents of the favorites folder in the browser.
            Process.Start(myFavoritesPath)
        End Sub

        ' Opens URLs and .html documents using Internet Explorer.
        Sub OpenWithArguments()
            ' URLs are not considered documents. They can only be opened
            ' by passing them as arguments.
            Process.Start("IExplore.exe", "www.northwindtraders.com")

            ' Start a Web page using a browser associated with .html and .asp files.
            Process.Start("IExplore.exe", "C:\myPath\myFile.htm")
            Process.Start("IExplore.exe", "C:\myPath\myFile.asp")
        End Sub

        ' Uses the ProcessStartInfo class to start new processes,
        ' both in a minimized mode.
        Sub OpenWithStartInfo()
            Dim startInfo As New ProcessStartInfo("IExplore.exe")
            startInfo.WindowStyle = ProcessWindowStyle.Minimized

            Process.Start(startInfo)

            startInfo.Arguments = "www.northwindtraders.com"

            Process.Start(startInfo)
        End Sub

        Shared Sub Main()
            ' Get the path that stores favorite links.
            Dim myFavoritesPath As String = Environment.GetFolderPath(Environment.SpecialFolder.Favorites)

            Dim myProcess As New MyProcess()

            myProcess.OpenApplication(myFavoritesPath)
            myProcess.OpenWithArguments()
            myProcess.OpenWithStartInfo()
        End Sub
    End Class
End Namespace 'MyProcessSample

注釈

インスタンスを指定してプロセス リソースを開始するには、このオーバーロードを ProcessStartInfo 使用します。 オーバーロードは、リソースを新 Process しいオブジェクトに関連付けます。

注意

開始する実行可能ファイルのアドレスが URL の場合、プロセスは開始されず、 null 返されます。

このオーバーロードを使用すると、最初に新しい Process インスタンスを作成せずにプロセスを開始できます。 パラメーターでこのオーバーロードを ProcessStartInfo 使用することは、新しい Process インスタンスを作成し、その StartInfo プロパティを設定し、インスタンスを呼び出す Start 明示的な手順の Process 代わりに使用します。

インスタンスを ProcessStartInfo パラメーターとして使用すると、呼び出し Start に渡される内容を最も制御して を呼び出し、プロセスを開始できます。 ファイル名またはファイル名と引数のみを渡す必要がある場合は、新しい ProcessStartInfo インスタンスを作成する必要はありませんが、これはオプションです。 設定する必要がある唯一 Process.StartInfo のプロパティは、 FileName プロパティです。 プロパティは FileName 実行可能ファイルを表す必要はありません。 拡張子がシステムにインストールされているアプリケーションに関連付けられている任意の種類のファイルにすることができます。 たとえば、FileNameメモ帳などのエディターにテキスト ファイルが関連付けられている場合は、プロパティに.txt拡張子を付けたり、word などのワープロ ツールに.docファイルを関連付けた場合は.doc拡張子Microsoft持つことができます。

ClickOnce アプリケーションを起動するには、最初にアプリケーションをインストールした場所 (Web アドレスなど) を指定します。 ハード ドライブにインストールされている場所を指定して ClickOnce アプリケーションを起動しないでください。

ProcessStartInfo.UserNameインスタンスの プロパティと ProcessStartInfo.Password プロパティがStartInfo設定されている場合、アンマネージドCreateProcessWithLogonW関数が呼び出され、プロパティ値が true または プロパティ値ProcessWindowStyle.Hiddenである場合ProcessStartInfo.CreateNoWindowでも、新しいウィンドウでプロセスがProcessStartInfo.WindowStyle開始されます。 プロパティが のProcessStartInfo.Domain場合、ProcessStartInfo.UserNameプロパティは nullUPN 形式である必要があります。ユーザー@DNS_domain_name

他のオーバーロードとは異なり、パラメーターを持たない の Start オーバーロードはメンバーではありません static 。 インスタンスを既に作成 Process し、開始情報 (ファイル名を含む) を指定し、プロセス リソースを開始して既存 Process のインスタンスに関連付ける場合は、そのオーバーロードを使用します。 既存のコンポーネントのプロセスを static 開始するのではなく、新しい Process コンポーネントを作成する場合は、いずれかのオーバーロードを使用します。 このオーバーロードとパラメーターを持たないオーバーロードの両方を使用すると、インスタンスを使用してプロセス リソースの開始情報を ProcessStartInfo 指定できます。

システムでパス変数を引用符で囲んで宣言している場合、その場所で見つかるプロセスを開始するときに、そのパスを完全修飾する必要があります。 そうしないと、システムはそのパスを見つけられません。 たとえば、c:\mypath がパスに含まれておらず、それを path = %path%;"c:\mypath"` のように引用符を使用して追加した場合、c:\mypath 内の任意のプロセスを開始するときに、それを完全修飾する必要があります。

注意

ASP.NET Web ページとサーバー コントロール コードは、Web サーバー上の ASP.NET ワーカー プロセスのコンテキストで実行されます。 ASP.NET Web ページまたはサーバー コントロールで メソッドを使用 Start すると、アクセス許可が制限された Web サーバー上で新しいプロセスが実行されます。 プロセスはクライアント ブラウザーと同じコンテキストで開始されず、ユーザー デスクトップにアクセスできません。

を使用 Start してプロセスを開始するたびに、プロセスを閉じる必要があるか、システム リソースが失われるリスクがあります。 または Killを使用してプロセスをCloseMainWindow閉じます。 プロセスが既に閉じているかどうかを確認する場合は、そのプロパティを HasExited 使用します。

ここでは、マネージド スレッドのアパートメントの状態に関する注意が必要です。 が true パラメーターのstartInfo場合UseShellExecuteは、 メソッドに 属性[STAThread]を設定して、アプリケーションにスレッド モデルをmain()設定していることを確認します。 それ以外の場合は、マネージド スレッドをunknown状態にするか、状態にMTA置くことができます。後者は とtrue競合しますUseShellExecute。 一部のメソッドでは、アパートメントの状態が である必要はありません unknown。 状態が明示的に設定されていない場合、アプリケーションでこのようなメソッドが検出されると、既定値 MTAは に設定され、一度設定されると、アパートメントの状態を変更することはできません。 ただし、 MTA オペレーティング システム シェルがスレッドを管理しているときに例外がスローされます。

こちらもご覧ください

適用対象

Start()

この Process コンポーネントの StartInfo プロパティで指定されたプロセス リソースを起動 (または再利用) し、コンポーネントに関連付けます。

public:
 bool Start();
public bool Start ();
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public bool Start ();
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
public bool Start ();
member this.Start : unit -> bool
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
member this.Start : unit -> bool
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
member this.Start : unit -> bool
Public Function Start () As Boolean

戻り値

プロセス リソースが起動された場合は true。新しいプロセス リソースが起動されなかった場合は false (既存のプロセスを再利用した場合など)。

属性

例外

Process コンポーネントの StartInfo にファイル名が指定されませんでした。

または

UseShellExecute プロパティの StartInfo メンバーは true ですが、 RedirectStandardInputRedirectStandardOutput、または RedirectStandardErrortrueです。

関連付けられているファイルを開いているときにエラーが発生しました。

プロセス オブジェクトは既には破棄されています。

メソッドはシェルがサポートされていない Nano Server (.NET Core のみ) などのオペレーティング システムではサポートされていません。

次の例では、 クラスのインスタンスを Process 使用してプロセスを開始します。

#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

int main()
{
    Process^ myProcess = gcnew Process;

    try
    {
        myProcess->StartInfo->UseShellExecute = false;
        // You can start any process, HelloWorld is a do-nothing example.
        myProcess->StartInfo->FileName = "C:\\HelloWorld.exe";
        myProcess->StartInfo->CreateNoWindow = true;
        myProcess->Start();
        // This code assumes the process you are starting will terminate itself. 
        // Given that it is started without a window so you cannot terminate it 
        // on the desktop, it must terminate itself or you can do it programmatically
        // from this application using the Kill method.
    }
    catch ( Exception^ e ) 
    {
        Console::WriteLine( e->Message );
    }
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            try
            {
                using (Process myProcess = new Process())
                {
                    myProcess.StartInfo.UseShellExecute = false;
                    // You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                    myProcess.StartInfo.CreateNoWindow = true;
                    myProcess.Start();
                    // This code assumes the process you are starting will terminate itself.
                    // Given that it is started without a window so you cannot terminate it
                    // on the desktop, it must terminate itself or you can do it programmatically
                    // from this application using the Kill method.
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        Public Shared Sub Main()
            Try
                Using myProcess As New Process()

                    myProcess.StartInfo.UseShellExecute = False
                    ' You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"
                    myProcess.StartInfo.CreateNoWindow = True
                    myProcess.Start()
                    ' This code assumes the process you are starting will terminate itself. 
                    ' Given that it is started without a window so you cannot terminate it 
                    ' on the desktop, it must terminate itself or you can do it programmatically
                    ' from this application using the Kill method.
                End Using
            Catch e As Exception
                Console.WriteLine((e.Message))
            End Try
        End Sub
    End Class
End Namespace

注釈

このオーバーロードを使用して、プロセス リソースを開始し、現在 Process のコンポーネントに関連付けます。 戻り値 true は、新しいプロセス リソースが開始されたことを示します。 プロパティのメンバーStartInfoによってFileName指定されたプロセス リソースがコンピューターで既に実行されている場合、追加のプロセス リソースは開始されません。 代わりに、実行中のプロセス リソースが再利用され、 false 返されます。

ClickOnce アプリケーションを起動するには、最初にアプリケーションをインストールした場所 (Web アドレスなど) を指定します。 ハード ドライブにインストールされている場所を指定して ClickOnce アプリケーションを起動しないでください。

注意

Visual Studio を使用している場合、 メソッドの Start このオーバーロードは、コンポーネントをデザイナーにドラッグ Process した後にコードに挿入するオーバーロードです。 ウィンドウを Properties 使用してカテゴリを StartInfo 展開し、適切な値を プロパティに書き込 FileName みます。 フォームのプロシージャに変更が InitializeComponent 表示されます。

のこのオーバーロード Start はメソッドではありません static 。 クラスの Process インスタンスから呼び出す必要があります。 を呼び出すStart前に、最初にこのProcessインスタンスのプロパティ情報を指定StartInfoする必要があります。この情報は、開始するプロセス リソースを決定するために使用されるためです。

メソッドの他の Start オーバーロードはメンバーです static 。 メソッドのこれらのオーバーロードを呼び出す前に、 Process コンポーネントのインスタンスを作成する必要はありません。 代わりに、 クラス自体をProcess呼び出Startすことができます。プロセスが開始されると、新しいProcessコンポーネントが作成されます。 または、 null は、プロセスが再利用された場合に返されます。 プロセス リソースは、 メソッドによって返される新しい Process コンポーネントに自動的に Start 関連付けられます。

メンバーをStartInfo使用して、Windows Start メニューのRunダイアログ ボックスの機能を複製できます。 コマンド ラインに入力できるものは、 プロパティで適切な値 StartInfo を設定することで開始できます。 設定する必要がある唯一 StartInfo のプロパティは、 FileName プロパティです。 プロパティは FileName 実行可能ファイルである必要はありません。 拡張子がシステムにインストールされているアプリケーションに関連付けられている任意の種類のファイルにすることができます。 たとえば、FileNameメモ帳などのエディターにテキスト ファイルが関連付けられている場合は、プロパティに.txt拡張子を付けたり、word などのワープロ ツールに.docファイルを関連付けた場合は.doc拡張子Microsoft持つことができます。

コマンド ラインでは、特定の種類のファイルに対して実行するアクションを指定できます。 たとえば、ドキュメントを印刷したり、テキスト ファイルを編集したりできます。 プロパティの メンバーを使用して、 Verb これらのアクションを StartInfo 指定します。 他の種類のファイルの場合は、ダイアログ ボックスからファイルを起動するときに、コマンド ライン引数を Run 指定できます。 たとえば、 としてブラウザーを指定する場合は、URL を引数として FileName渡すことができます。 これらの引数は、プロパティArgumentsStartInfoメンバーで指定できます。

システムでパス変数を引用符で囲んで宣言している場合、その場所で見つかるプロセスを開始するときに、そのパスを完全修飾する必要があります。 そうしないと、システムはそのパスを見つけられません。 たとえば、c:\mypath がパスに含まれておらず、それを path = %path%;"c:\mypath"` のように引用符を使用して追加した場合、c:\mypath 内の任意のプロセスを開始するときに、それを完全修飾する必要があります。

注意

ASP.NET Web ページとサーバー コントロール コードは、Web サーバー上の ASP.NET ワーカー プロセスのコンテキストで実行されます。 ASP.NET Web ページまたはサーバー コントロールで メソッドを使用 Start すると、アクセス許可が制限された Web サーバー上で新しいプロセスが実行されます。 プロセスはクライアント ブラウザーと同じコンテキストで開始されず、ユーザー デスクトップにアクセスできません。

を使用 Start してプロセスを開始するたびに、プロセスを閉じる必要があるか、システム リソースが失われるリスクがあります。 または Killを使用してプロセスをCloseMainWindow閉じます。 プロセスが既に閉じているかどうかを確認する場合は、そのプロパティを HasExited 使用します。

ここでは、マネージド スレッドでのアパートメントの状態に関する注意が必要です。 がtrueプロセス コンポーネントの StartInfo プロパティにある場合UseShellExecuteは、 メソッドに 属性[STAThread]を設定して、アプリケーションにスレッド モデルをmain()設定していることを確認します。 それ以外の場合は、マネージド スレッドを unknown 状態にするか、状態にMTA置くことができます。後者は とtrue競合しますUseShellExecute。 一部のメソッドでは、アパートメントの状態が である unknown必要はありません。 状態が明示的に設定されていない場合、アプリケーションでこのようなメソッドが検出されると、既定値は に MTA設定され、一度設定されると、アパートメントの状態を変更することはできません。 ただし、 MTA オペレーティング システム シェルがスレッドを管理しているときに例外がスローされます。

こちらもご覧ください

適用対象

Start(String, IEnumerable<String>)

アプリケーションの名前とコマンド ライン引数のセットを指定してプロセス リソースを起動します。

public:
 static System::Diagnostics::Process ^ Start(System::String ^ fileName, System::Collections::Generic::IEnumerable<System::String ^> ^ arguments);
public static System.Diagnostics.Process Start (string fileName, System.Collections.Generic.IEnumerable<string> arguments);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
public static System.Diagnostics.Process Start (string fileName, System.Collections.Generic.IEnumerable<string> arguments);
[System.Runtime.Versioning.UnsupportedOSPlatform("ios")]
[System.Runtime.Versioning.UnsupportedOSPlatform("tvos")]
[System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")]
public static System.Diagnostics.Process Start (string fileName, System.Collections.Generic.IEnumerable<string> arguments);
static member Start : string * seq<string> -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
static member Start : string * seq<string> -> System.Diagnostics.Process
[<System.Runtime.Versioning.UnsupportedOSPlatform("ios")>]
[<System.Runtime.Versioning.UnsupportedOSPlatform("tvos")>]
[<System.Runtime.Versioning.SupportedOSPlatform("maccatalyst")>]
static member Start : string * seq<string> -> System.Diagnostics.Process
Public Shared Function Start (fileName As String, arguments As IEnumerable(Of String)) As Process

パラメーター

fileName
String

プロセスで実行する文書またはアプリケーション ファイルの名前。

arguments
IEnumerable<String>

プロセスを起動するときに渡すコマンド ライン引数。

戻り値

プロセス リソースに関連付けられている新しい Process。プロセス リソースが起動されていない場合は null

属性

注釈

各引数は、必要に応じて自動的にエスケープされます。

適用対象