ProcessStartInfo.FileName Właściwość

Definicja

Pobiera lub ustawia aplikację lub dokument do uruchomienia.

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

Wartość właściwości

Nazwa aplikacji do uruchomienia lub nazwa dokumentu typu pliku skojarzonego z aplikacją i ma do niej domyślną otwartą akcję. Wartością domyślną jest ciąg pusty ("").

Atrybuty

Przykłady

#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 it 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 it 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 it 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

Uwagi

Przed rozpoczęciem procesu należy ustawić co najmniej FileName właściwość. Nazwa pliku to dowolna aplikacja lub dokument. Dokument jest definiowany jako dowolny typ pliku, który ma skojarzona z nim otwartą lub domyślną akcję. Zarejestrowane typy plików i skojarzone z nimi aplikacje dla komputera można wyświetlić za pomocą okna dialogowego Opcje folderów , które jest dostępne za pośrednictwem systemu operacyjnego. Przycisk Zaawansowane prowadzi do okna dialogowego, które pokazuje, czy istnieje otwarta akcja skojarzona z określonym zarejestrowanym typem pliku.

Zestaw dostępnych typów plików zależy częściowo od wartości UseShellExecute właściwości. Jeśli UseShellExecute jest to true, możesz uruchomić dowolny dokument i wykonać operacje na pliku, takie jak drukowanie, ze składnikiem Process . Gdy UseShellExecute jest to false, można uruchomić tylko pliki wykonywalne za pomocą Process składnika.

Aplikację ClickOnce można uruchomić, ustawiając FileName właściwość na lokalizację (na przykład adres internetowy), z której pierwotnie zainstalowano aplikację. Nie uruchamiaj aplikacji ClickOnce, określając jego zainstalowaną lokalizację na dysku twardym.

Ważne

Użycie wystąpienia tego obiektu z niezaufanymi danymi jest zagrożeniem bezpieczeństwa. Użyj tego obiektu tylko z zaufanymi danymi. Aby uzyskać więcej informacji, zobacz Weryfikowanie wszystkich danych wejściowych.

Dotyczy