ProcessStartInfo.UseShellExecute Properti

Definisi

Mendapatkan atau menetapkan nilai yang menunjukkan apakah akan menggunakan shell sistem operasi untuk memulai proses.

public:
 property bool UseShellExecute { bool get(); void set(bool value); };
public bool UseShellExecute { get; set; }
member this.UseShellExecute : bool with get, set
Public Property UseShellExecute As Boolean

Nilai Properti

true jika shell harus digunakan saat memulai proses; false jika proses harus dibuat langsung dari file yang dapat dieksekusi. Defaultnya adalah false (atau true di aplikasi .NET Framework).

Pengecualian

Upaya untuk mengatur nilai ke true pada aplikasi Universal Windows Platform (UWP) terjadi.

Contoh

// Run "csc.exe /r:System.dll /out:sample.exe stdstr.cs". UseShellExecute is false because we're specifying
// an executable directly and in this case depending on it being in a PATH folder. By setting
// RedirectStandardOutput to true, the output of csc.exe is directed to the Process.StandardOutput stream
// which is then displayed in this console window directly.
using (Process compiler = new Process())
{
    compiler.StartInfo.FileName = "csc.exe";
    compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
    compiler.StartInfo.UseShellExecute = false;
    compiler.StartInfo.RedirectStandardOutput = true;
    compiler.Start();

    Console.WriteLine(compiler.StandardOutput.ReadToEnd());

    compiler.WaitForExit();
}
' Run "vbc.exe /reference:Microsoft.VisualBasic.dll /out:sample.exe stdstr.vb". UseShellExecute is False 
' because we're specifying an executable directly and in this case depending on it being in a PATH folder. 
' By setting RedirectStandardOutput to True, the output of csc.exe is directed to the Process.StandardOutput 
' stream which is then displayed in this console window directly.    
Using compiler As New Process()
    compiler.StartInfo.FileName = "vbc.exe"
    compiler.StartInfo.Arguments = "/reference:Microsoft.VisualBasic.dll /out:sample.exe stdstr.vb"
    compiler.StartInfo.UseShellExecute = False
    compiler.StartInfo.RedirectStandardOutput = True
    compiler.Start()

    Console.WriteLine(compiler.StandardOutput.ReadToEnd())

    compiler.WaitForExit()
End Using

Keterangan

Kelas ProcessStartInfo menentukan sekumpulan nilai yang digunakan saat Anda memulai proses.

Mengatur properti UseShellExecute ke false memungkinkan Anda mengalihkan aliran input, output, dan kesalahan.

Kata "shell" dalam konteks ini (UseShellExecute) mengacu pada shell grafis (mirip dengan shell Windows) daripada shell perintah (misalnya, bash atau sh) dan memungkinkan pengguna meluncurkan aplikasi grafis atau membuka dokumen.

Note

UseShellExecute harus false jika properti UserName bukan null atau string kosong, atau InvalidOperationException akan dilempar ketika metode Process.Start(ProcessStartInfo) dipanggil.

Ketika Anda menggunakan shell sistem operasi untuk memulai proses, Anda dapat memulai dokumen apa pun (yang merupakan jenis file terdaftar yang terkait dengan executable yang memiliki tindakan terbuka default) dan melakukan operasi pada file, seperti pencetakan, dengan menggunakan Process objek . Ketika UseShellExecute adalah false, Anda hanya dapat memulai executable dengan menggunakan Process objek .

Note

UseShellExecute harus true jika Anda mengatur properti ke ErrorDialogtrue.

WorkingDirectory

Properti WorkingDirectory bernilai berbeda tergantung pada nilai UseShellExecute properti. Ketika UseShellExecute adalah true, WorkingDirectory properti menentukan lokasi yang dapat dieksekusi. Jika WorkingDirectory adalah string kosong, diasumsikan bahwa direktori saat ini berisi executable.

Ketika UseShellExecute adalah false, WorkingDirectory properti tidak digunakan untuk menemukan executable. Sebaliknya, ini hanya digunakan oleh proses yang dimulai dan hanya memiliki arti dalam konteks proses baru. Ketika UseShellExecute adalah false, properti FileName dapat berupa jalur lengkap ke file yang dapat dieksekusi, atau nama file eksekusi sederhana yang akan dicari sistem dalam folder yang ditentukan oleh variabel lingkungan PATH. Interpretasi jalur pencarian tergantung pada sistem operasi. Untuk informasi selengkapnya, masukkan HELP PATH atau man sh pada prompt perintah.

Berlaku untuk

Lihat juga