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, 並提供目的地 url 做為ProcessStartInfo引數。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. [ Advanced ] 按鈕會出現一個對話方塊, 顯示是否有開啟的動作與特定的已註冊檔案類型相關聯。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. 不過, 您可以使用RedirectStandardInputRedirectStandardOutputRedirectStandardError屬性, 讓進程取得輸入或將輸出傳回至檔案或其他裝置。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. 如果StandardInput您使用元件上Process的、 StandardError StandardOutput或屬性, 您必須先在屬性上設定對應的值。ProcessStartInfoIf 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, 則新的進程會繼承RedirectStandardInput呼叫進程的標準輸入、標準輸出和標準錯誤資料流程, 除非分別為、 RedirectStandardOutputRedirectStandardError屬性設定為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. 當立即呼叫端沒有完全信任許可權時,就會擲回。SecurityExceptionA 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
, 用於呼叫的ProcessStartInfo成員。for calling members of ProcessStartInfo. 需求值: LinkDemand;命名許可權集合: FullTrustDemand value: LinkDemand; Named Permission Sets: FullTrust.

適用於

另請參閱