ProcessStartInfo 類別

定義

指定一組啟動處理序時所使用的值。

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 屬性。 檔名是任何應用程式或檔。 在這裡,檔會定義為任何具有開啟或默認動作與其相關聯的文件類型。 您可以使用 [ 資料夾選項 ] 對話框,透過作業系統來檢視已註冊的檔類型及其相關聯的應用程式。 [ 進階 ] 按鈕會導致對話框顯示是否有與特定已註冊檔類型相關聯的開啟動作。

此外,您可以設定其他屬性,以定義要使用該檔案採取的動作。 您可以指定屬性之屬性Verb類型的FileName特定值。 例如,您可以指定文件類型的「列印」。 此外,您可以將屬性值指定 Arguments 為命令行自變數,以傳遞至檔案的開啟程式。 例如,如果您在屬性中 FileName 指定文字編輯器應用程式,您可以使用 Arguments 屬性來指定要由編輯器開啟的文字檔。

標準輸入通常是鍵盤,而標準輸出和標準錯誤通常是監視畫面。 不過,您可以使用 RedirectStandardInputRedirectStandardOutputRedirectStandardError 屬性,讓行程從檔案或其他裝置取得輸入或傳回輸出。 如果您在元件上使用 StandardInputProcessStandardOutputStandardError 屬性,您必須先在 屬性上ProcessStartInfo設定對應的值。 否則,當您讀取或寫入數據流時,系統會擲回例外狀況。

UseShellExecute設定 屬性,以指定是否要使用操作系統殼層啟動進程。 如果 UseShellExecute 設定為 false,則新進程會繼承呼叫進程的標準輸入、標準輸出和標準錯誤數據流,除非 RedirectStandardInput分別將、 RedirectStandardOutputRedirectStandardError 屬性設定為 true

您可以將任何 ProcessStartInfo 屬性的值變更為進程開始的時間。 啟動程序之後,變更這些值並沒有任何作用。

重要

使用此物件的執行個體時,若並用了不信任的資料,會造成安全性上的風險。 使用此物件時,請一律使用信任的資料。 如需詳細資訊,請參閱 驗證所有輸入

注意

此類別包含套用至所有成員之類別層級的連結需求。 SecurityException當立即呼叫端沒有完全信任權限時,會擲回 。 如需安全性需求的詳細資訊,請參閱 連結需求

建構函式

ProcessStartInfo()

不指定用來啟動處理序的檔案名稱,初始化 ProcessStartInfo 類別的新執行個體。

ProcessStartInfo(String)

初始化 ProcessStartInfo 類別的新執行個體,並指定用來啟動處理序的檔案名稱 (例如應用程式或文件)。

ProcessStartInfo(String, IEnumerable<String>)

指定一組啟動處理序時所使用的值。

ProcessStartInfo(String, String)

初始化 ProcessStartInfo 類別的新執行個體,並指定用來啟動處理序的應用程式檔案名稱,以及指定要傳遞至應用程式的命令列引數集。

屬性

ArgumentList

取得啟動應用程式時要使用的命令列引數集合。 新增至清單的字串無須先行逸出。

Arguments

取得或設定啟動應用程式時要使用的命令列引數集。

CreateNoWindow

取得或設定值,表示是否要在新視窗中啟動處理序。

Domain

取得或設定值,識別在啟動處理序時要使用的網域。 如果此值為 null,則必須以 UPN 格式指定 UserName 屬性。

Environment

取得套用至這個處理序及其子處理序的環境變數。

EnvironmentVariables

取得檔案的搜尋路徑、暫存檔的目錄、應用程式特定選項和其他類似的資訊。

ErrorDialog

取得或設定值,表示是否要在無法啟動處理序時向使用者顯示錯誤對話方塊。

ErrorDialogParentHandle

取得或設定視窗控制代碼,以便在無法啟動處理序而顯示錯誤對話方塊時使用。

FileName

取得或設定要啟動的應用程式或文件。

LoadUserProfile

取得或設定值,表示是否要從登錄載入 Windows 使用者設定檔。

Password

取得或設定安全字串,其中包含啟動處理序時要使用的使用者密碼。

PasswordInClearText

取得或設定啟動處理程序時使用之純文字格式的使用者密碼。

RedirectStandardError

取得或設定值,表示應用程式的錯誤輸出是否寫入至 StandardError 資料流。

RedirectStandardInput

取得或設定值,表示應用程式的輸入是否從 StandardInput 資料流讀取。

RedirectStandardOutput

取得或設定值,表示應用程式的文字輸出是否寫入至 StandardOutput 資料流。

StandardErrorEncoding

取得或設定錯誤輸出的慣用編碼。

StandardInputEncoding

取得或設定標準輸出的慣用編碼。

StandardOutputEncoding

取得或設定標準輸出的慣用編碼。

UseCredentialsForNetworkingOnly

指定一組啟動處理序時所使用的值。

UserName

取得或設定要在啟動處理序時使用的使用者名稱。 如果您使用 UPN 格式 user@DNS_domain_nameDomain 屬性必須為 null

UseShellExecute

取得或設定值,表示是否要使用作業系統 Shell 來啟動處理序。

Verb

取得或設定動詞命令 (Verb),用於開啟由 FileName 屬性所指定的應用程式或文件時。

Verbs

取得動詞命令集,這個動詞命令集與 FileName 屬性所指定的檔案類型相關聯。

WindowStyle

取得或設定視窗狀態,用於啟動處理序時。

WorkingDirectory

UseShellExecute 屬性為 false 時,取得或設定要啟動之處理序的工作目錄。 當 UseShellExecutetrue 時,取得或設定包含要啟動之處理序的目錄。

方法

Equals(Object)

判斷指定的物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前執行個體的 Type

(繼承來源 Object)
MemberwiseClone()

建立目前 Object 的淺層複製。

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。

(繼承來源 Object)

適用於

另請參閱