ProcessStartInfo 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
指定一組啟動處理序時所使用的值。
public ref class ProcessStartInfo sealed
public sealed class ProcessStartInfo
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
public sealed class ProcessStartInfo
type ProcessStartInfo = class
[<System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))>]
type ProcessStartInfo = class
Public NotInheritable Class ProcessStartInfo
- 繼承
-
ProcessStartInfo
- 屬性
範例
下列程式碼範例示範如何使用 ProcessStartInfo 類別來啟動 Internet Explorer。 目的地 URL 會以引數的形式 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 。 當您使用 Process 類別啟動進程時,除了附加至執行中的進程時,您還可以存取進程資訊。
您可以使用 ProcessStartInfo 類別,以更妥善地控制您啟動的程式。 您至少必須手動或使用 建構函式來設定 FileName 屬性。 檔案名是任何應用程式或檔。 這裡會將檔定義為任何具有開啟或預設動作與其相關聯的檔案類型。 您可以使用作業系統提供的 [ 資料夾選項 ] 對話方塊,檢視電腦的已註冊檔案類型及其相關聯的應用程式。 [ 進階 ] 按鈕會導致對話方塊顯示是否有與特定已註冊檔案類型相關聯的開啟動作。
此外,您可以設定其他屬性,以定義要使用該檔案採取的動作。 您可以指定屬性之 FileName 屬性 Verb 類型的特定值。 例如,您可以指定檔案類型的「列印」。 此外,您可以指定 Arguments 屬性值做為命令列引數,以傳遞至檔案的開啟程式。 例如,如果您在 屬性中 FileName 指定文字編輯器應用程式,您可以使用 Arguments 屬性來指定要由編輯器開啟的文字檔。
標準輸入通常是鍵盤,而標準輸出和標準錯誤通常是監視畫面。 不過,您可以使用 RedirectStandardInput 、 RedirectStandardOutput 和 RedirectStandardError 屬性,讓進程從 檔案或其他裝置取得輸入或傳回輸出。 如果您在 StandardInput 元件上使用 Process 、 StandardOutput 或 StandardError 屬性,您必須先在 屬性上 ProcessStartInfo 設定對應的值。 否則,當您讀取或寫入資料流程時,系統會擲回例外狀況。
UseShellExecute設定 屬性,以指定是否要使用作業系統殼層啟動進程。 如果 UseShellExecute 設定為 false
,則新進程會繼承呼叫進程的標準輸入、標準輸出和標準錯誤資料流程,除非 RedirectStandardInput 分別將 、 RedirectStandardOutput 或 RedirectStandardError 屬性設定為 true
。
您可以將任何 ProcessStartInfo 屬性的值變更為進程啟動的時間。 啟動程式之後,變更這些值就沒有任何作用。
重要
使用此物件的執行個體時,若並用了不信任的資料,會造成安全性上的風險。 使用此物件時,請一律使用信任的資料。 如需詳細資訊,請參閱 驗證所有輸入。
注意
此類別包含適用于所有成員之類別層級的連結需求。 SecurityException當立即呼叫端沒有完全信任許可權時,會擲回 。 如需安全性需求的詳細資訊,請參閱 連結需求。
建構函式
ProcessStartInfo() |
不指定用來啟動處理序的檔案名稱,初始化 ProcessStartInfo 類別的新執行個體。 |
ProcessStartInfo(String) |
初始化 ProcessStartInfo 類別的新執行個體,並指定用來啟動處理序的檔案名稱 (例如應用程式或文件)。 |
ProcessStartInfo(String, String) |
初始化 ProcessStartInfo 類別的新執行個體,並指定用來啟動處理序的應用程式檔案名稱,以及指定要傳遞至應用程式的命令列引數集。 |
屬性
ArgumentList |
取得啟動應用程式時要使用的命令列引數集合。 新增至清單的字串無須先行逸出。 |
Arguments |
取得或設定啟動應用程式時要使用的命令列引數集。 |
CreateNoWindow |
取得或設定值,表示是否要在新視窗中啟動處理序。 |
Domain |
取得或設定值,識別在啟動處理序時要使用的網域。 如果此值為 |
Environment |
取得套用至這個處理序及其子處理序的環境變數。 |
EnvironmentVariables |
取得檔案的搜尋路徑、暫存檔的目錄、應用程式特定選項和其他類似的資訊。 |
ErrorDialog |
取得或設定值,表示是否要在無法啟動處理序時向使用者顯示錯誤對話方塊。 |
ErrorDialogParentHandle |
取得或設定視窗控制代碼,以便在無法啟動處理序而顯示錯誤對話方塊時使用。 |
FileName |
取得或設定要啟動的應用程式或文件。 |
LoadUserProfile |
取得或設定值,表示是否要從登錄載入 Windows 使用者設定檔。 |
Password |
取得或設定安全字串,其中包含啟動處理序時要使用的使用者密碼。 |
PasswordInClearText |
取得或設定啟動處理程序時使用之純文字格式的使用者密碼。 |
RedirectStandardError |
取得或設定值,表示應用程式的錯誤輸出是否寫入至 StandardError 資料流。 |
RedirectStandardInput |
取得或設定值,表示應用程式的輸入是否從 StandardInput 資料流讀取。 |
RedirectStandardOutput |
取得或設定值,表示應用程式的文字輸出是否寫入至 StandardOutput 資料流。 |
StandardErrorEncoding |
取得或設定錯誤輸出的慣用編碼。 |
StandardInputEncoding |
取得或設定標準輸出的慣用編碼。 |
StandardOutputEncoding |
取得或設定標準輸出的慣用編碼。 |
UseCredentialsForNetworkingOnly |
指定一組啟動處理序時所使用的值。 |
UserName |
取得或設定要在啟動處理序時使用的使用者名稱。 如果您使用 UPN 格式 |
UseShellExecute |
取得或設定值,表示是否要使用作業系統 Shell 來啟動處理序。 |
Verb |
取得或設定動詞命令 (Verb),用於開啟由 FileName 屬性所指定的應用程式或文件時。 |
Verbs |
取得動詞命令集,這個動詞命令集與 FileName 屬性所指定的檔案類型相關聯。 |
WindowStyle |
取得或設定視窗狀態,用於啟動處理序時。 |
WorkingDirectory |
當 UseShellExecute 屬性為 |
方法
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |