Process.MainWindowHandle Property
Gets the window handle of the main window of the associated process.
[Visual Basic] Public ReadOnly Property MainWindowHandle As IntPtr [C#] public IntPtr MainWindowHandle {get;} [C++] public: __property IntPtr get_MainWindowHandle(); [JScript] public function get MainWindowHandle() : IntPtr;
Property Value
The system-generated window handle of the main window of the associated process.
Exceptions
| Exception Type | Condition |
|---|---|
| InvalidOperationException | The MainWindowHandle is not defined because the process has exited. |
| NotSupportedException | You are attempting to retrieve the MainWindowHandle for a process that is running on a remote computer. |
Remarks
You can get the MainWindowHandle property only for processes that are running on the local computer. The MainWindowHandle property is a value that uniquely identifies the window that is associated with the process.
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, the MainWindowHandle value is zero. If you have just started a process and want to use its main window handle, consider using the WaitForInputIdle method to allow the process to finish starting, ensuring that the main window handle has been created. Otherwise, an exception will be thrown.
Windows 98 Platform Note: This property is not available on this platform if you started the process with ProcessStartInfo.UseShellExecute set to true.
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:
- SecurityPermission for calling any members of System.Diagnostic.Process with full trust. Associated enumeration: PermissionState.Unrestricted
See Also
Process Class | Process Members | System.Diagnostics Namespace | MainWindowTitle | MainModule