ProcessStartInfo ProcessStartInfo ProcessStartInfo ProcessStartInfo Class

定義

指定啟動處理序時所使用之值的集合。Specifies a set of values that are used when you start a process.

public ref class ProcessStartInfo sealed
[System.ComponentModel.TypeConverter(typeof(System.ComponentModel.ExpandableObjectConverter))]
public sealed class ProcessStartInfo
type ProcessStartInfo = class
Public NotInheritable Class ProcessStartInfo
繼承
ProcessStartInfoProcessStartInfoProcessStartInfoProcessStartInfo
屬性

範例

下列程式碼範例示範如何使用ProcessStartInfo類別,以啟動 Internet Explorer,提供做為目的地 UrlProcessStartInfo引數。The following code example demonstrates how to use the ProcessStartInfo class to start Internet Explorer, providing the destination URLs as ProcessStartInfo arguments.

#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()
{
    // 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 = 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 'OpenApplication

        ' Opens urls and .html documents using Internet Explorer.
        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

        ' 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 '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

備註

ProcessStartInfo 可搭配使用Process元件。ProcessStartInfo is used together with the Process component. 當您啟動處理程序,使用Process類別,您可以存取附加至執行中處理序時,處理除了可用的資訊。When you start a process using the Process class, you have access to process information in addition to that available when attaching to a running process.

您可以使用ProcessStartInfo類別,以便更有效控制您所啟動的程序。You can use the ProcessStartInfo class for better control over the process you start. 您至少必須設定FileName屬性,以手動方式或使用建構函式。You must at least set the FileName property, either manually or using the constructor. 任何應用程式或文件的檔案名稱。The file name is any application or document. 以下文件會定義任何已開啟的檔案類型或預設與其相關聯的動作。Here a document is defined to be any file type that has an open or default action associated with it. 您可以為您的電腦檢視已註冊的檔案類型和其相關聯的應用程式,利用資料夾選項 對話方塊中,也就是透過作業系統提供。You can view registered file types and their associated applications for your computer by using the Folder Options dialog box, which is available through the operating system. 進階按鈕會導致顯示是否已註冊的特定檔案類型相關聯的開啟動作的對話方塊。The Advanced button leads to a dialog box that shows whether there is an open action associated with a specific registered file type.

此外,您可以設定其他屬性,定義要搭配此檔案所採取的動作。In addition, you can set other properties that define actions to take with that file. 您可以指定特定的型別值FileName屬性Verb屬性。You can specify a value specific to the type of the FileName property for the Verb property. 例如,您可以指定 「 列印 」 文件類型。For example, you can specify "print" for a document type. 此外,您可以指定Arguments来傳遞至檔案的開啟程序的命令列引數的屬性值。Additionally, you can specify Arguments property values to be command-line arguments to pass to the file's open procedure. 例如,如果您指定的文字編輯器應用程式中FileName屬性,您可以使用Arguments屬性來指定文字檔案編輯器開啟。For example, if you specify a text editor application in the FileName property, you can use the Arguments property to specify a text file to be opened by the editor.

標準輸入通常是鍵盤,標準輸出和標準錯誤通常會監視螢幕。Standard input is usually the keyboard, and standard output and standard error are usually the monitor screen. 不過,您可以使用RedirectStandardInputRedirectStandardOutput,和RedirectStandardError屬性,讓從取得輸入,或傳回輸出到檔案或其他裝置的程序。However, you can use the RedirectStandardInput, RedirectStandardOutput, and RedirectStandardError properties to cause the process to get input from or return output to a file or other device. 如果您使用StandardInputStandardOutput,或StandardError上的屬性Process元件,您必須先設定對應的值上ProcessStartInfo屬性。If you use the StandardInput, StandardOutput, or StandardError properties on the Process component, you must first set the corresponding value on the ProcessStartInfo property. 當您讀取或寫入資料流中,否則系統會擲回例外狀況。Otherwise, the system throws an exception when you read or write to the stream.

設定UseShellExecute屬性來指定是否使用作業系統 shell 啟動程序。Set the UseShellExecute property to specify whether to start the process by using the operating system shell. 如果UseShellExecute設定為false,新的處理序會繼承標準輸入中,標準輸出,並呼叫的標準錯誤資料流處理,除非RedirectStandardInputRedirectStandardOutput,或RedirectStandardError屬性,分別設定為true.If UseShellExecute is set to false, the new process inherits the standard input, standard output, and standard error streams of the calling process, unless the RedirectStandardInput, RedirectStandardOutput, or RedirectStandardError properties, respectively, are set to true.

您可以變更任何值ProcessStartInfo屬性的程序啟動的時間。You can change the value of any ProcessStartInfo property up to the time that the process starts. 啟動程序之後,變更這些值沒有任何作用。After you start the process, changing these values has no effect.

注意

這個類別包含在類別層級套用至所有成員的連結要求。This class contains a link demand at the class level that applies to all members. ASecurityException立即呼叫端沒有完全信任權限時,會擲回。A SecurityException is thrown when the immediate caller does not have full-trust permission. 如需安全性需求的詳細資訊,請參閱連結要求For details about security demands, see Link Demands.

建構函式

ProcessStartInfo() ProcessStartInfo() ProcessStartInfo() ProcessStartInfo()

不指定用來啟動處理序的檔案名稱,初始化 ProcessStartInfo 類別的新執行個體。Initializes a new instance of the ProcessStartInfo class without specifying a file name with which to start the process.

ProcessStartInfo(String) ProcessStartInfo(String) ProcessStartInfo(String) ProcessStartInfo(String)

初始化 ProcessStartInfo 類別的新執行個體,並指定用來啟動處理序的檔案名稱 (例如應用程式或文件)。Initializes a new instance of the ProcessStartInfo class and specifies a file name such as an application or document with which to start the process.

ProcessStartInfo(String, String) ProcessStartInfo(String, String) ProcessStartInfo(String, String) ProcessStartInfo(String, String)

初始化 ProcessStartInfo 類別的新執行個體,並指定用來啟動處理序的應用程式檔案名稱,以及指定要傳遞至應用程式的命令列引數集。Initializes a new instance of the ProcessStartInfo class, specifies an application file name with which to start the process, and specifies a set of command-line arguments to pass to the application.

屬性

ArgumentList ArgumentList ArgumentList ArgumentList

取得啟動應用程式時要使用的命令列引數集合。Gets a collection of command-line arguments to use when starting the application.

Arguments Arguments Arguments Arguments

取得或設定啟動應用程式時要使用的命令列引數集。Gets or sets the set of command-line arguments to use when starting the application.

CreateNoWindow CreateNoWindow CreateNoWindow CreateNoWindow

取得或設定值,指出是否要在新視窗中啟動處理序。Gets or sets a value indicating whether to start the process in a new window.

Domain Domain Domain Domain

取得或設定值,識別在啟動處理序時要使用的網域。Gets or sets a value that identifies the domain to use when starting the process. 如果此值為 null,則必須以 UPN 格式指定 UserName 屬性。If this value is null, the UserName property must be specified in UPN format.

Environment Environment Environment Environment

取得套用至這個處理序及其子處理序的環境變數。Gets the environment variables that apply to this process and its child processes.

EnvironmentVariables EnvironmentVariables EnvironmentVariables EnvironmentVariables

取得檔案的搜尋路徑、暫存檔的目錄、特定應用程式的選項和其他類似的資訊。Gets search paths for files, directories for temporary files, application-specific options, and other similar information.

ErrorDialog ErrorDialog ErrorDialog ErrorDialog

取得或設定值,指出錯誤對話方塊是否要在處理序無法啟動時向使用者顯示。Gets or sets a value indicating whether an error dialog box is displayed to the user if the process cannot be started.

ErrorDialogParentHandle ErrorDialogParentHandle ErrorDialogParentHandle ErrorDialogParentHandle

取得或設定視窗控制代碼,以便在無法啟動處理序而顯示錯誤對話方塊時使用。Gets or sets the window handle to use when an error dialog box is shown for a process that cannot be started.

FileName FileName FileName FileName

取得或設定要啟動的應用程式或文件。Gets or sets the application or document to start.

LoadUserProfile LoadUserProfile LoadUserProfile LoadUserProfile

取得或設定值,指出 Windows 使用者設定檔是否要從登錄載入。Gets or sets a value that indicates whether the Windows user profile is to be loaded from the registry.

Password Password Password Password

取得或設定安全字串,其中包含啟動處理序時要使用的使用者密碼。Gets or sets a secure string that contains the user password to use when starting the process.

PasswordInClearText PasswordInClearText PasswordInClearText PasswordInClearText

取得或設定啟動處理程序時使用之純文字格式的使用者密碼。Gets or sets the user password in clear text to use when starting the process.

RedirectStandardError RedirectStandardError RedirectStandardError RedirectStandardError

取得或設定值,指出應用程式的錯誤輸出是否寫入至 StandardError 資料流。Gets or sets a value that indicates whether the error output of an application is written to the StandardError stream.

RedirectStandardInput RedirectStandardInput RedirectStandardInput RedirectStandardInput

取得或設定值,指出應用程式的輸入是否從 StandardInput 資料流讀取。Gets or sets a value indicating whether the input for an application is read from the StandardInput stream.

RedirectStandardOutput RedirectStandardOutput RedirectStandardOutput RedirectStandardOutput

取得或設定值,表示應用程式的文字輸出是否寫入至 StandardOutput 資料流。Gets or sets a value that indicates whether the textual output of an application is written to the StandardOutput stream.

StandardErrorEncoding StandardErrorEncoding StandardErrorEncoding StandardErrorEncoding

取得或設定錯誤輸出的慣用編碼。Gets or sets the preferred encoding for error output.

StandardInputEncoding StandardInputEncoding StandardInputEncoding StandardInputEncoding
StandardOutputEncoding StandardOutputEncoding StandardOutputEncoding StandardOutputEncoding

取得或設定標準輸出的慣用編碼。Gets or sets the preferred encoding for standard output.

UserName UserName UserName UserName

取得或設定要在啟動處理序時使用的使用者名稱。Gets or sets the user name to use when starting the process. 如果您使用 UPN 格式 user@DNS_domain_nameDomain 屬性必須為 nullIf you use the UPN format, user@DNS_domain_name, the Domain property must be null.

UseShellExecute UseShellExecute UseShellExecute UseShellExecute

取得或設定值,指出是否要使用作業系統 Shell 來啟動處理序。Gets or sets a value indicating whether to use the operating system shell to start the process.

Verb Verb Verb Verb

取得或設定動詞命令 (Verb),用於開啟由 FileName 屬性所指定的應用程式或文件時。Gets or sets the verb to use when opening the application or document specified by the FileName property.

Verbs Verbs Verbs Verbs

取得動詞命令集,這個動詞命令集與由 FileName 屬性所指定的檔案類型相關聯。Gets the set of verbs associated with the type of file specified by the FileName property.

WindowStyle WindowStyle WindowStyle WindowStyle

取得或設定視窗狀態,用於處理序啟動時。Gets or sets the window state to use when the process is started.

WorkingDirectory WorkingDirectory WorkingDirectory WorkingDirectory

UseShellExecute 屬性為 false 時,取得或設定要啟動之處理序的工作目錄。When the UseShellExecute property is false, gets or sets the working directory for the process to be started. UseShellExecutetrue 時,取得或設定包含要啟動之處理序的目錄。When UseShellExecute is true, gets or sets the directory that contains the process to be started.

方法

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(Inherited from Object)

安全性

SecurityPermission
呼叫成員ProcessStartInfofor calling members of ProcessStartInfo. 要求值: LinkDemand;[NIB:具名使用權限集合](https://msdn.microsoft.com/library/08250d67-c99d-4ab0-8d2b-b0e12019f6e3): FullTrustDemand value: LinkDemand; [NIB: Named Permission Sets](https://msdn.microsoft.com/library/08250d67-c99d-4ab0-8d2b-b0e12019f6e3): FullTrust.

適用於

另請參閱