I'm learning on how to use the Process class. I create a form and during the form load, I'd like to open the notepad as well. See my code below.
My problem is: After open the notepad, is it possible to get the handle of the notepad through process.Handle property?
I try the code as below but error occur as it come to
hwnd = myproc.Handle
Error :
An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll
Additional information: No process is associated with this object.
Can anybody tell me how to get its handle?
Thank you.
My problem is: After open the notepad, is it possible to get the handle of the notepad through process.Handle property?
I try the code as below but error occur as it come to
hwnd = myproc.Handle
Error :
An unhandled exception of type 'System.InvalidOperationException' occurred in system.dll
Additional information: No process is associated with this object.
Can anybody tell me how to get its handle?
Thank you.
Visual Basic:
Inherits System.Windows.Forms.Form
Dim WithEvents myproc As System.Diagnostics.Process
Dim hwnd As IntPtr
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myproc = New System.Diagnostics.Process()
' Do not receive an event when the process exits.
myproc.EnableRaisingEvents = True ' False
' Start Notepad, and assign it to the process component.
myproc.Start("Notepad.exe")
' This prevents the window from accepting a close before it has
' fully opened.
'myproc.WaitForInputIdle()
hwnd = myproc.Handle
End Sub
Last edited by a moderator: