ProcessStartInfo.FileName Properti

Definisi

Mendapatkan atau mengatur aplikasi atau dokumen untuk memulai.

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

Nilai Properti

Nama aplikasi yang akan dimulai, atau nama dokumen jenis file yang terkait dengan aplikasi dan yang memiliki tindakan terbuka default yang tersedia untuknya. Defaultnya adalah string kosong ("").

Atribut

Contoh

#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

Keterangan

Anda harus mengatur setidaknya FileName properti sebelum memulai proses. Nama file adalah aplikasi atau dokumen apa pun. Dokumen didefinisikan sebagai jenis file apa pun yang memiliki tindakan terbuka atau default yang terkait dengannya. Anda dapat melihat jenis file terdaftar dan aplikasi terkaitnya untuk komputer Anda dengan menggunakan kotak dialog Opsi Folder , yang tersedia melalui sistem operasi. Tombol Tingkat Lanjut mengarah ke kotak dialog yang memperlihatkan apakah ada tindakan terbuka yang terkait dengan jenis file terdaftar tertentu.

Kumpulan jenis file yang tersedia untuk Anda bergantung sebagian pada nilai UseShellExecute properti . Jika UseShellExecute adalah true, Anda dapat memulai dokumen apa pun dan melakukan operasi pada file, seperti pencetakan, dengan Process komponen . Ketika UseShellExecute adalah false, Anda hanya dapat memulai executable dengan Process komponen .

Anda dapat memulai aplikasi ClickOnce dengan mengatur FileName properti ke lokasi (misalnya, alamat Web) tempat Anda awalnya menginstal aplikasi. Jangan memulai aplikasi ClickOnce dengan menentukan lokasi yang terinstal pada hard disk Anda.

Penting

Menggunakan instans objek ini dengan data yang tidak tepercaya adalah risiko keamanan. Gunakan objek ini hanya dengan data tepercaya. Untuk informasi selengkapnya, lihat Memvalidasi Semua Input.

Berlaku untuk