title: Clicking a button in a Visual Basic application from .NET
body: <p>I am creating a console application that should call a VB application MyProj.exe and triggers a button click event on the same.</p>
  
  <p>As of now I am able to run the executable file of the VB project but I wanted to fire the certain button click event from console application.</p>
  
  <pre><code>System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
  startInfo.FileName = @"C:\New\MyProj.exe";
  System.Diagnostics.Process.Start(startInfo);
  </code></pre>
  
  <p>i have tried with the below link - that is not working for me
  <a href="http://www.codeproject.com/Articles/14519/Using-Windows-APIs-from-C-again" rel="nofollow">http://www.codeproject.com/Articles/14519/Using-Windows-APIs-from-C-again</a></p>
  
  <p>--  the hwndChild after executing every statement is coming as "zero"</p>
  
  <pre><code>    //Get a handle for the "5" button
              hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","5");
  
              //send BN_CLICKED message
              SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
  
              //Get a handle for the "+" button
              hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","*");
  
              //send BN_CLICKED message
              SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
  
              //Get a handle for the "2" button
              hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","2");
  
              //send BN_CLICKED message
              SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
  
              //Get a handle for the "=" button
              hwndChild = FindWindowEx((IntPtr)hwnd,IntPtr.Zero,"Button","=");
  
              //send BN_CLICKED message
              SendMessage((int)hwndChild,BN_CLICKED,0,IntPtr.Zero);
  </code></pre>
  
  <p>Thanks so much codecaster - but i would require little more help</p>
  
  <pre><code>     #define AMP_PAUSE 40046
      HWND hwnd = FindWindow("Winamp v1.x", 0);
      if(hwnd) SendMessage(hwnd, WM_COMMAND, AMP_PAUSE, 0);
  </code></pre>
  
  <p>button1 is the id of the button; and Call_Method() is the procedure which is called when we click button1.</p>
  
  <p>can you pls help how to write the above code in c#</p>