Process.StartInfo プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
public:
property System::Diagnostics::ProcessStartInfo ^ StartInfo { System::Diagnostics::ProcessStartInfo ^ get(); void set(System::Diagnostics::ProcessStartInfo ^ value); };
public System.Diagnostics.ProcessStartInfo StartInfo { get; set; }
[System.ComponentModel.Browsable(false)]
public System.Diagnostics.ProcessStartInfo StartInfo { get; set; }
member this.StartInfo : System.Diagnostics.ProcessStartInfo with get, set
[<System.ComponentModel.Browsable(false)>]
member this.StartInfo : System.Diagnostics.ProcessStartInfo with get, set
Public Property StartInfo As ProcessStartInfo
プロパティ値
プロセスを起動するときに使用するデータを表す ProcessStartInfo。 これらの引数には、プロセスの起動時に使用する実行可能ファイルまたは文書の名前があります。
- 属性
例外
StartInfo を指定する値は null
です。
.NET Core と .NET 5 以降のみ: メソッドを Start() 使用してプロセスを開始できませんでした。
例
次の例では、 に実行するファイル、それに対して実行されたアクション、およびユーザー インターフェイスを表示するかどうかを設定 StartInfo します。 その他の例については、 クラスのプロパティのリファレンス ページを ProcessStartInfo 参照してください。
#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
注釈
StartInfo は、プロセスの開始に使用するパラメーターのセットを表します。 が呼び出されると Start 、 StartInfo が使用され、開始するプロセスが指定されます。 設定に必要な StartInfo メンバーは、 FileName プロパティのみです。 プロパティを指定してプロセスをFileName開始することは、Windows の [スタート] メニューの [実行] ダイアログ ボックスに情報を入力するのと似ています。 したがって、 プロパティは FileName 実行可能ファイルを表す必要はありません。 拡張子がシステムにインストールされているアプリケーションに関連付けられている任意のファイルの種類を指定できます。 たとえばFileName、メモ帳などのエディターにテキスト ファイルを関連付けた場合は .txt 拡張子を持つことができます。また、word などのワープロ ツールに.docファイルを関連付けた場合は.doc Microsoftできます。 同様に、[ 実行 ] ダイアログ ボックスで、.exe拡張子の有無にかかわらず実行可能ファイル名を受け入れるのと同じ方法で、.exe拡張機能はメンバーで FileName 省略可能です。 たとえば、 プロパティを FileName "Notepad.exe" または "メモ帳" に設定できます。
ClickOnce アプリケーションを起動するには、 プロパティを FileName 、最初にアプリケーションをインストールした場所 (Web アドレスなど) に設定します。 ハード ドライブにインストールされている場所を指定して ClickOnce アプリケーションを起動しないでください。
ファイル名に実行できないファイル (.doc ファイルなど) が含まれている場合は、ファイルに対して実行するアクションを指定する動詞を含めることができます。 たとえば、.doc拡張子で終わるファイルの を "Print" に設定 Verb できます。 プロパティの値を FileName 手動で入力する場合、プロパティで指定されたファイル名に拡張子を付ける Verb 必要はありません。 ただし、 プロパティを Verbs 使用して使用できる動詞を決定する場合は、拡張機能を含める必要があります。
プロパティで指定されたパラメーターは、 StartInfo プロセスで メソッドを呼び出 Start す時点まで変更できます。 プロセスを開始した後、値を StartInfo 変更しても、関連付けられているプロセスに影響を与えたり再起動したりすることはありません。 プロパティと プロパティをStart(ProcessStartInfo)設定して メソッドProcessStartInfo.UserNameを呼び出すと、アンマネージCreateProcessWithLogonW
関数が呼び出されます。これにより、プロパティ値が true
または プロパティ値である場合CreateNoWindowでも、新しいウィンドウでプロセスがWindowStyleHidden開始ProcessStartInfo.Passwordされます。
メソッドによって返されるオブジェクトの Process プロパティにのみアクセスStartInfoするStart必要があります。 たとえば、 によってGetProcesses返されるオブジェクトの StartInfo プロパティにはProcessアクセスしないでください。 それ以外の場合、.NET Core StartInfo では、 プロパティは をInvalidOperationExceptionスローし、.NET Frameworkダミー オブジェクトをProcessStartInfo返します。
プロセスが開始されると、ファイル名は (読み取り専用) MainModule プロパティを設定するファイルです。 プロセスの開始後にプロセスに関連付けられている実行可能ファイルを取得する場合は、 プロパティを MainModule 使用します。 関連付けられたプロセスが開始されていないインスタンスのProcess実行可能ファイルを設定する場合は、 プロパティの FileName メンバーをStartInfo使用します。 プロパティのメンバーは、プロセスの StartInfo メソッドに渡される引数であるため、関連付けられたプロセスの開始後にStartFileNameプロパティを変更しても、プロパティはリセットMainModuleされません。 これらのプロパティは、関連付けられているプロセスを初期化するためにのみ使用されます。
適用対象
こちらもご覧ください
フィードバック
フィードバックの送信と表示