ProcessStartInfo.FileName 屬性

定義

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

public:
 property System::String ^ FileName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.SettingsBindable(true)]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
[System.ComponentModel.TypeConverter("System.Diagnostics.Design.StringValueConverter, System.Design, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public string FileName { get; set; }
member this.FileName : string with get, set
Public Property FileName As String

屬性值

要啟動的應用程式名稱,或是與應用程式相關且具有可用預設開啟動作的檔案類型的文件名稱。The name of the application to start, or the name of a document of a file type that is associated with an application and that has a default open action available to it. 預設為空字串 ("")。The default is an empty string ("").

屬性

範例

#using <System.dll>
using namespace System;
using namespace System::Diagnostics;
using namespace System::ComponentModel;

int main()
{
    Process^ myProcess = gcnew Process;

    try
    {
        myProcess->StartInfo->UseShellExecute = false;
        // You can start any process, HelloWorld is a do-nothing example.
        myProcess->StartInfo->FileName = "C:\\HelloWorld.exe";
        myProcess->StartInfo->CreateNoWindow = true;
        myProcess->Start();
        // This code assumes the process you are starting will terminate itself. 
        // Given that is is started without a window so you cannot terminate it 
        // on the desktop, it must terminate itself or you can do it programmatically
        // from this application using the Kill method.
    }
    catch ( Exception^ e ) 
    {
        Console::WriteLine( e->Message );
    }
}
using System;
using System.Diagnostics;
using System.ComponentModel;

namespace MyProcessSample
{
    class MyProcess
    {
        public static void Main()
        {
            try
            {
                using (Process myProcess = new Process())
                {
                    myProcess.StartInfo.UseShellExecute = false;
                    // You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe";
                    myProcess.StartInfo.CreateNoWindow = true;
                    myProcess.Start();
                    // This code assumes the process you are starting will terminate itself. 
                    // Given that is is started without a window so you cannot terminate it 
                    // on the desktop, it must terminate itself or you can do it programmatically
                    // from this application using the Kill method.
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
    }
}
Imports System.Diagnostics
Imports System.ComponentModel

Namespace MyProcessSample
    Class MyProcess
        Public Shared Sub Main()
            Try
                Using myProcess As New Process()

                    myProcess.StartInfo.UseShellExecute = False
                    ' You can start any process, HelloWorld is a do-nothing example.
                    myProcess.StartInfo.FileName = "C:\\HelloWorld.exe"
                    myProcess.StartInfo.CreateNoWindow = True
                    myProcess.Start()
                    ' This code assumes the process you are starting will terminate itself. 
                    ' Given that is is started without a window so you cannot terminate it 
                    ' on the desktop, it must terminate itself or you can do it programmatically
                    ' from this application using the Kill method.
                End Using
            Catch e As Exception
                Console.WriteLine((e.Message))
            End Try
        End Sub
    End Class
End Namespace

備註

開始處理常式之前,您必須至少設定 FileName 屬性。You must set at least the FileName property before you start the process. 檔案名為任何應用程式或檔。The file name is any application or document. 檔會定義為具有與其相關聯之開啟或預設動作的任何檔案類型。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.

您可以使用的一組檔案類型,取決於 UseShellExecute 屬性的值。The set of file types available to you depends in part on the value of the UseShellExecute property. 如果 UseShellExecutetrue,您可以使用 Process 元件啟動任何檔,並對檔案執行作業(例如列印)。If UseShellExecute is true, you can start any document and perform operations on the file, such as printing, with the Process component. UseShellExecute false 時,您只能使用 Process 元件來啟動可執行檔。When UseShellExecute is false, you can start only executables with the Process component.

您可以啟動 ClickOnce 應用程式,方法是將 [FileName] 屬性設定為您原先安裝應用程式的位置(例如,網址)。You can start a ClickOnce application by setting the FileName property to the location (for example, a Web address) from which you originally installed the application. 不要啟動 ClickOnce 應用程式,請在硬碟上指定安裝的位置。Do not start a ClickOnce application by specifying its installed location on your hard disk.

適用於