Process.MainWindowTitle Properti

Definisi

Mendapatkan keterangan jendela utama proses.

public:
 property System::String ^ MainWindowTitle { System::String ^ get(); };
public string MainWindowTitle { get; }
member this.MainWindowTitle : string
Public ReadOnly Property MainWindowTitle As String

Nilai Properti

Judul jendela utama proses.

Pengecualian

Properti MainWindowTitle tidak ditentukan karena proses telah keluar.

Anda mencoba mengakses MainWindowTitle properti untuk proses yang berjalan pada komputer jarak jauh. Properti ini hanya tersedia untuk proses yang berjalan pada komputer lokal.

Contoh

Contoh berikut memulai instans Notepad dan mengambil keterangan jendela utama proses.

using System;
using System.Diagnostics;

class MainWindowTitleClass
{
    public static void Main()
    {
        try
        {
            // Create an instance of process component.
            using (Process myProcess = new Process())
            {
                // Create an instance of 'myProcessStartInfo'.
                ProcessStartInfo myProcessStartInfo = new ProcessStartInfo();
                myProcessStartInfo.FileName = "notepad";
                myProcess.StartInfo = myProcessStartInfo;
                // Start process.
                myProcess.Start();
                // Allow the process to finish starting.
                myProcess.WaitForInputIdle();
                Console.Write("Main window Title : " + myProcess.MainWindowTitle);

                myProcess.CloseMainWindow();
            }
        }
        catch (Exception e)
        {
            Console.Write($" Message : {e.Message}");
        }
    }
}
open System.Diagnostics

try
    // Create an instance of process component.
    use myProcess = new Process()
    // Create an instance of 'myProcessStartInfo'.
    let myProcessStartInfo = ProcessStartInfo()
    myProcessStartInfo.FileName <- "notepad"
    myProcess.StartInfo <- myProcessStartInfo
    // Start process.
    myProcess.Start() |> ignore
    // Allow the process to finish starting.
    myProcess.WaitForInputIdle() |> ignore
    printfn $"Main window Title : {myProcess.MainWindowTitle}"

    myProcess.CloseMainWindow() |> ignore
with e ->
    printfn $" Message : {e.Message}"
Imports System.Diagnostics

Class MainWindowTitleClass
    Public Shared Sub Main()
        Try
            ' Create an instance of process component.
            Using myProcess As New Process()
                ' Create an instance of 'myProcessStartInfo'.
                Dim myProcessStartInfo As New ProcessStartInfo()
                myProcessStartInfo.FileName = "notepad"
                myProcess.StartInfo = myProcessStartInfo
                ' Start process.
                myProcess.Start()
                ' Allow the process to finish starting.
                myProcess.WaitForInputIdle()
                Console.Write("Main window Title : " + myProcess.MainWindowTitle)

                myProcess.CloseMainWindow()
            End Using
        Catch e As Exception
            Console.Write($" Message : {e.Message}")
        End Try
    End Sub
End Class

Keterangan

Proses memiliki jendela utama yang terkait dengannya hanya jika proses memiliki antarmuka grafis. Jika proses terkait tidak memiliki jendela utama (sehingga MainWindowHandle nol), atau jika sistem tidak dapat menentukan bahwa ada jendela utama (seperti mungkin kasus pada beberapa platform Unix), MainWindowTitle adalah string kosong ("").

Jika Anda baru saja memulai proses dan ingin menggunakan judul jendela utamanya, pertimbangkan untuk menggunakan WaitForInputIdle metode untuk memungkinkan proses selesai dimulai, memastikan bahwa handel jendela utama telah dibuat. Jika tidak, sistem melemparkan pengecualian.

Note

Jendela utama adalah jendela yang saat ini memiliki fokus; perhatikan bahwa ini mungkin bukan jendela utama untuk proses tersebut. Anda harus menggunakan Refresh metode untuk menyegarkan Process objek untuk mendapatkan handel jendela utama terbaru jika telah berubah.

Berlaku untuk