次の方法で共有


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)

ソース:
Process.Unix.cs
ソース:
Process.Unix.cs
ソース:
Process.Unix.cs
ソース:
Process.Unix.cs
ソース:
Process.Unix.cs

重要

この 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 以外のプロセスを返す場合があります。 この場合、開始されたプロセスがそれ自体の既存のインスタンスをアクティブ化してから終了した可能性があります。

属性

例外

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

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

-又は-

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

-又は-

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

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

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

注釈

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

Important

信頼されていないデータを使用してこのメソッドを呼び出すことは、セキュリティ上のリスクです。 このメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。

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

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

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

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

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

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

適用対象

Start(String, String, SecureString, String)

ソース:
Process.Unix.cs
ソース:
Process.Unix.cs
ソース:
Process.Unix.cs
ソース:
Process.Unix.cs
ソース:
Process.Unix.cs

重要

この 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 以外のプロセスを返す場合があります。 この場合、開始されたプロセスがそれ自体の既存のインスタンスをアクティブ化してから終了した可能性があります。

属性

例外

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

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

-又は-

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();
        }
    }
}
// NOTE: This example requires a text.txt file file in your Documents folder
open System
open System.Diagnostics
open System.Security
open System.ComponentModel

printf "Enter your domain: "
let domain = stdin.ReadLine()
printf "Enter you user name: "
let uname = stdin.ReadLine()
printf "Enter your password: "
let password = new SecureString()

let mutable key = Console.ReadKey(true)

while key.Key <> ConsoleKey.Enter do
    // Ignore any key out of range.
    if int key.Key >= 33 && int key.Key <= 90 && key.Key <> ConsoleKey.Enter then
        // Append the character to the password.
        password.AppendChar key.KeyChar
        Console.Write "*"

    key <- Console.ReadKey(true)

printfn ""

try
    printfn "\nTrying to launch NotePad using your login information..."
    Process.Start("notepad.exe", uname, password, domain) |> ignore
with :? Win32Exception as ex ->
    printfn $"{ex.Message}"

let path = Environment.GetFolderPath Environment.SpecialFolder.MyDocuments + @"\"

try
    // The following call to Start succeeds if test.txt exists.
    printfn "\nTrying to launch 'text.txt'..."
    Process.Start $"{path}text.txt" |> ignore
with :? Win32Exception as ex ->
    printfn $"{ex.Message}"

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.
        printfn "\nTrying to launch 'text.txt' with your login information..."
        Process.Start($"{path}text.txt", uname, password, domain) |> ignore
    with :? Win32Exception as ex ->
        printfn $"{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

注釈

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

Important

信頼されていないデータを使用してこのメソッドを呼び出すことは、セキュリティ上のリスクです。 このメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。

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

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

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

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

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

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

適用対象

Start(String, String)

ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs

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

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

パラメーター

fileName
String

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

arguments
String

プロセスの開始時に渡すコマンド ライン引数。

返品

プロセス リソースに関連付けられている新しい Process 。プロセス リソースが開始されていない場合は null 。 同じプロセスの既に実行中のインスタンスと共に開始された新しいプロセスは、他のプロセスとは独立している点に注意してください。 さらに、Start は、 HasExited プロパティが既に true に設定されている null 以外のプロセスを返す場合があります。 この場合、開始されたプロセスがそれ自体の既存のインスタンスをアクティブ化してから終了した可能性があります。

属性

例外

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

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

-又は-

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

-又は-

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

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

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

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

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();
        }
    }
}
module processstartstatic

open System
open System.Diagnostics

// Opens the Internet Explorer application.
let openApplication (myFavoritesPath: string) =
    // Start Internet Explorer. Defaults to the home page.
    Process.Start "IExplore.exe" |> ignore

    // Display the contents of the favorites folder in the browser.
    Process.Start myFavoritesPath |> ignore

// Opens urls and .html documents using Internet Explorer.
let openWithArguments () =
    // url's are not considered documents. They can only be opened
    // by passing them as arguments.
    Process.Start("IExplore.exe", "www.northwindtraders.com") |> ignore

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

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
let openWithStartInfo () =
    let startInfo = ProcessStartInfo "IExplore.exe"
    startInfo.WindowStyle <- ProcessWindowStyle.Minimized

    Process.Start startInfo |> ignore

    startInfo.Arguments <- "www.northwindtraders.com"

    Process.Start startInfo |> ignore

// Get the path that stores favorite links.
let myFavoritesPath = Environment.GetFolderPath Environment.SpecialFolder.Favorites

openApplication myFavoritesPath
openWithArguments ()
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 オブジェクトに関連付けます。

Important

信頼されていないデータを使用してこのメソッドを呼び出すことは、セキュリティ上のリスクです。 このメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。

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

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

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

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

引用符を使用してシステムで宣言されたパス変数がある場合は、その場所で見つかったプロセスを開始するときに、そのパスを完全に修飾する必要があります。 それ以外の場合、システムはパスを見つけることができません。 たとえば、 c:\mypath がパス内になく、引用符 ( path = %path%;"c:\mypath") を使用して追加する場合は、 c:\mypath のプロセスを開始するときに完全に修飾する必要があります。

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

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

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

こちらもご覧ください

適用対象

Start(String)

ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs

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

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

パラメーター

fileName
String

プロセスで実行するドキュメントまたはアプリケーション ファイルの名前。

返品

プロセス リソースに関連付けられている新しい Process 。プロセス リソースが開始されていない場合は null 。 同じプロセスの既に実行中のインスタンスと共に開始された新しいプロセスは、他のプロセスとは独立している点に注意してください。 さらに、Start は、 HasExited プロパティが既に true に設定されている null 以外のプロセスを返す場合があります。 この場合、開始されたプロセスがそれ自体の既存のインスタンスをアクティブ化してから終了した可能性があります。

属性

例外

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

-又は-

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

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

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

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

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();
        }
    }
}
module processstartstatic

open System
open System.Diagnostics

// Opens the Internet Explorer application.
let openApplication (myFavoritesPath: string) =
    // Start Internet Explorer. Defaults to the home page.
    Process.Start "IExplore.exe" |> ignore

    // Display the contents of the favorites folder in the browser.
    Process.Start myFavoritesPath |> ignore

// Opens urls and .html documents using Internet Explorer.
let openWithArguments () =
    // url's are not considered documents. They can only be opened
    // by passing them as arguments.
    Process.Start("IExplore.exe", "www.northwindtraders.com") |> ignore

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

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
let openWithStartInfo () =
    let startInfo = ProcessStartInfo "IExplore.exe"
    startInfo.WindowStyle <- ProcessWindowStyle.Minimized

    Process.Start startInfo |> ignore

    startInfo.Arguments <- "www.northwindtraders.com"

    Process.Start startInfo |> ignore

// Get the path that stores favorite links.
let myFavoritesPath = Environment.GetFolderPath Environment.SpecialFolder.Favorites

openApplication myFavoritesPath
openWithArguments ()
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 オブジェクトに関連付けます。

Important

信頼されていないデータを使用してこのメソッドを呼び出すことは、セキュリティ上のリスクです。 このメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。

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

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

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

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

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

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

引用符を使用してシステムで宣言されたパス変数がある場合は、その場所で見つかったプロセスを開始するときに、そのパスを完全に修飾する必要があります。 それ以外の場合、システムはパスを見つけることができません。 たとえば、 c:\mypath がパス内になく、引用符 ( path = %path%;"c:\mypath") を使用して追加する場合は、 c:\mypath のプロセスを開始するときに完全に修飾する必要があります。

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

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

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

こちらもご覧ください

適用対象

Start(ProcessStartInfo)

ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs

プロセス開始情報 (たとえば、開始するプロセスのファイル名) を含むパラメーターで指定されたプロセス リソースを開始し、リソースを新しい Process コンポーネントに関連付けます。

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

パラメーター

startInfo
ProcessStartInfo

ファイル名やコマンド ライン引数など、プロセスの開始に使用される情報を含む ProcessStartInfo

返品

プロセス リソースに関連付けられている新しい Process 。プロセス リソースが開始されていない場合は null 。 同じプロセスの既に実行中のインスタンスと共に開始された新しいプロセスは、他のプロセスとは独立している点に注意してください。 さらに、Start は、 HasExited プロパティが既に true に設定されている null 以外のプロセスを返す場合があります。 この場合、開始されたプロセスがそれ自体の既存のインスタンスをアクティブ化してから終了した可能性があります。

属性

例外

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;
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();
        }
    }
}
module processstartstatic

open System
open System.Diagnostics

// Opens the Internet Explorer application.
let openApplication (myFavoritesPath: string) =
    // Start Internet Explorer. Defaults to the home page.
    Process.Start "IExplore.exe" |> ignore

    // Display the contents of the favorites folder in the browser.
    Process.Start myFavoritesPath |> ignore

// Opens urls and .html documents using Internet Explorer.
let openWithArguments () =
    // url's are not considered documents. They can only be opened
    // by passing them as arguments.
    Process.Start("IExplore.exe", "www.northwindtraders.com") |> ignore

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

// Uses the ProcessStartInfo class to start new processes,
// both in a minimized mode.
let openWithStartInfo () =
    let startInfo = ProcessStartInfo "IExplore.exe"
    startInfo.WindowStyle <- ProcessWindowStyle.Minimized

    Process.Start startInfo |> ignore

    startInfo.Arguments <- "www.northwindtraders.com"

    Process.Start startInfo |> ignore

// Get the path that stores favorite links.
let myFavoritesPath = Environment.GetFolderPath Environment.SpecialFolder.Favorites

openApplication myFavoritesPath
openWithArguments ()
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 オブジェクトに関連付けます。

Important

信頼されていないデータを使用してこのメソッドを呼び出すことは、セキュリティ上のリスクです。 このメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。

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

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

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

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

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

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

引用符を使用してシステムで宣言されたパス変数がある場合は、その場所で見つかったプロセスを開始するときに、そのパスを完全に修飾する必要があります。 それ以外の場合、システムはパスを見つけることができません。 たとえば、 c:\mypath がパス内になく、引用符 ( path = %path%;"c:\mypath") を使用して追加する場合は、 c:\mypath のプロセスを開始するときに完全に修飾する必要があります。

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

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

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

こちらもご覧ください

適用対象

Start()

ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs

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

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

返品

true プロセス リソースが開始された場合。 false 新しいプロセス リソースが開始されていない場合 (たとえば、既存のプロセスが再利用される場合)。

属性

例外

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

-又は-

RedirectStandardInputRedirectStandardOutput、またはRedirectStandardErrortrueされている間、StartInfo プロパティのUseShellExecute メンバーがtrueされます。

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

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

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

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

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);
            }
        }
    }
}
open System.Diagnostics

try
    use 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() |> ignore
// 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.
with e ->
    printfn $"{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 アプリケーションを起動しないでください。

Important

信頼されていないデータでこの型のインスタンスを使用することは、セキュリティ上のリスクです。 このオブジェクトは、信頼できるデータでのみ使用します。 詳細については、「すべての入力を検証する」を参照してください。

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

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

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

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

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

引用符を使用してシステムで宣言されたパス変数がある場合は、その場所で見つかったプロセスを開始するときに、そのパスを完全に修飾する必要があります。 それ以外の場合、システムはパスを見つけることができません。 たとえば、 c:\mypath がパス内になく、引用符 ( path = %path%;"c:\mypath") を使用して追加する場合は、 c:\mypath のプロセスを開始するときに完全に修飾する必要があります。

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

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

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

こちらもご覧ください

適用対象

Start(String, IEnumerable<String>)

ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs
ソース:
Process.cs

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

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

パラメーター

fileName
String

プロセスで実行するドキュメントまたはアプリケーション ファイルの名前。

arguments
IEnumerable<String>

プロセスの開始時に渡すコマンド ライン引数。

返品

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

属性

注釈

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

Important

信頼されていないデータを使用してこのメソッドを呼び出すことは、セキュリティ上のリスクです。 このメソッドは、信頼できるデータでのみ呼び出します。 詳細については、「すべての入力を検証する」を参照してください。

適用対象