Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Process.MainWindowTitle Property

Gets the caption of the main window of the process.

[Visual Basic]
Public ReadOnly Property MainWindowTitle As String
[C#]
public string MainWindowTitle {get;}
[C++]
public: __property String* get_MainWindowTitle();
[JScript]
public function get MainWindowTitle() : String;

Property Value

The process's main window title.

Remarks

A process has a main window associated with it only if the process has a graphical interface. If the associated process does not have a main window (so that MainWindowHandle is zero), MainWindowTitle is an empty string (""). If you have just started a process and want to use its main window title, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. Otherwise, the system throws an exception.

Windows 98 Platform Note:  This property is not available on this platform if you started the process with ProcessStartInfo.UseShellExecute set to true.

Example

[Visual Basic, C#, C++] The following example starts an instance of Notepad and retrieves the caption of the main window of the process.

[Visual Basic] 
Imports System
Imports System.Diagnostics

Class MainWindowTitleClass
   Public Shared Sub Main()
      Try

         ' Create an instance of process component.
         Dim 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()
         myProcess.Close()
      Catch e As Exception
         Console.Write(" Message : " + e.Message)
      End Try
   End Sub 'Main
End Class 'MainWindowTitleClass

[C#] 
using System;
using System.Diagnostics;

class MainWindowTitleClass
{
   public static void Main()
   {
      try
      {

         // Create an instance of process component.
         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();
         myProcess.Close();
      }
      catch(Exception e)
      {
         Console.Write(" Message : " + e.Message);
      }
    
   }
}


[C++] 
#using <mscorlib.dll>
#using <System.dll>

using namespace System;
using namespace System::Diagnostics;

int main() {
    try {
        // Create an instance of process component.
        Process* myProcess = new Process();
        // Create an instance of 'myProcessStartInfo'.
        ProcessStartInfo* myProcessStartInfo = new ProcessStartInfo();
        myProcessStartInfo->FileName = S"notepad";
        myProcess->StartInfo = myProcessStartInfo;
        // Start process.
        myProcess->Start();
        // Allow the process to finish starting.
        myProcess->WaitForInputIdle();
        Console::Write(S"Main window Title : {0}", myProcess->MainWindowTitle);

        myProcess->CloseMainWindow();
        myProcess->Close();
    } catch (Exception* e) {
        Console::Write(S" Message : {0}", e->Message);
    }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

.NET Framework Security: 

See Also

Process Class | Process Members | System.Diagnostics Namespace

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.