cheng_sh Posted May 28, 2003 Posted May 28, 2003 (edited) 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. 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 Edited May 28, 2003 by divil Quote
AndreRyan Posted May 28, 2003 Posted May 28, 2003 hWnd s are for windows not applications. Does notepad actually start? Quote .Net allows software to be written for any version of Windows and not break like Unmanaged applications unless using Unmanaged procedures like APIs. If your program uses large amounts of memory but releases it when something else needs it, then what's the problem?
*Gurus* Derek Stone Posted May 28, 2003 *Gurus* Posted May 28, 2003 Your code should read: myproc = Process.Start("notepad") As it stands now you have no application associated with your Process object. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.