ProcessStartInfo クラス
アセンブリ: System (system.dll 内)
構文
解説
メモ |
---|
このクラスに適用される HostProtectionAttribute 属性の Resources プロパティの値は、SharedState または SelfAffectingProcessMgmt です。HostProtectionAttribute は、デスクトップ アプリケーション (一般的には、アイコンをダブルクリック、コマンドを入力、またはブラウザに URL を入力して起動するアプリケーション) には影響しません。詳細については、HostProtectionAttribute クラスのトピックまたは「SQL Server プログラミングとホスト保護属性」を参照してください。 |
ProcessStartInfo は、Process コンポーネントと組み合わせて使用します。Process クラスを使用してプロセスを起動すると、実行中のプロセスに接続するときに利用できる情報だけでなく、プロセス情報にもアクセスできます。
ProcessStartInfo クラスを使用して、起動するプロセスをさらに制御できます。少なくとも、手動またはコンストラクタを使用して、FileName プロパティを設定する必要があります。ファイル名は、任意のアプリケーションまたはドキュメントにします。ここでいうドキュメントとは、"open" という既定のアクションが関連付けられている任意のファイル タイプです。登録されているファイル タイプと、コンピュータ上でこれらに関連付けられているアプリケーションは、オペレーティング システムを通じて利用できる [フォルダ オプション] ダイアログ ボックスで参照できます。[詳細設定] ボタンを使用すると、登録されている特定のファイル タイプに "open" アクションが関連付けられているかどうかを示すダイアログ ボックスが表示されます。
さらにその他のプロパティを設定して、そのファイルに対して実行するアクションを定義できます。FileName プロパティの種類に固有の値を Verb プロパティに指定できます。たとえば、ドキュメントの種類に対して "印刷" を指定できます。さらに、ファイルのオープン プロシージャに渡すコマンド ライン引数になるように、Arguments プロパティ値を指定できます。たとえば、FileName プロパティにテキスト エディタ アプリケーションを指定すると、Arguments プロパティを使用してエディタで開くテキスト ファイルを指定できます。
標準入力は通常、キーボードで、標準出力と標準エラー出力は通常、モニタ画面です。ただし、RedirectStandardInput、RedirectStandardOutput、RedirectStandardError の各プロパティを使用すると、プロセスが入力を取得したり出力を返す先をファイルまたはその他のデバイスにできます。Process コンポーネントの StandardInput、StandardOutput、または StandardError の各プロパティを使用する場合は、まず対応する値を ProcessStartInfo プロパティに設定する必要があります。設定しないと、ストリームの読み取りまたは書き込みを実行したときに、例外がスローされます。
UseShellExecute を設定し、オペレーティング システムのシェルを使用してプロセスを起動するかどうかを指定します。
ProcessStartInfo プロパティの値を変更できるのは、プロセスを起動するまでです。プロセスを開始した後で、これらの値を変更しても影響はありません。
Imports System Imports System.Diagnostics Imports System.ComponentModel Namespace MyProcessSample _ '/ <summary> '/ Shell for the sample. '/ </summary> Class MyProcess '/ <summary> '/ Opens the Internet Explorer application. '/ </summary> 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 'OpenApplication '/ <summary> '/ Opens urls and .html documents using Internet Explorer. '/ </summary> Sub 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") End Sub 'OpenWithArguments '/ <summary> '/ Uses the ProcessStartInfo class to start new processes, both in a minimized '/ mode. '/ </summary> 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 'OpenWithStartInfo 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 'Main End Class 'MyProcess End Namespace 'MyProcessSample
using System; using System.Diagnostics; using System.ComponentModel; namespace MyProcessSample { /// <summary> /// Shell for the sample. /// </summary> class MyProcess { /// <summary> /// Opens the Internet Explorer application. /// </summary> 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); } /// <summary> /// Opens urls and .html documents using Internet Explorer. /// </summary> 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"); } /// <summary> /// Uses the ProcessStartInfo class to start new processes, both in a minimized /// mode. /// </summary> 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(); } } }
#using <System.dll> using namespace System; using namespace System::Diagnostics; using namespace System::ComponentModel; /// <summary> /// Opens the Internet Explorer application. /// </summary> 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 ); } /// <summary> /// Opens urls and .html documents using Internet Explorer. /// </summary> 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" ); } /// <summary> /// Uses the ProcessStartInfo class to start new processes, both in a minimized /// mode. /// </summary> 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(); }
System.Diagnostics.ProcessStartInfo
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- ProcessStartInfo クラスのページへのリンク