I can not figure out why my send messages will only work when debugging. When I launch from the .exe file it appears that they are not firing. The code is just suppose to click a button on en external application.

Code:
private void TransferBuild (object sender, EventArgs e)  //Button Click Event
{
string sync = @"C:\USCG_IMS\SyncMgr.exe"; if (File.Exists(sync)) {
this.Hide(); ActiveSync.FileName = sync; ActiveSync.CreateNoWindow = false; ActiveSync.UseShellExecute = false; SyncRun.StartInfo = ActiveSync; SyncRun.EnableRaisingEvents = true; SyncRun.Exited += new EventHandler (SyncRun_Exited); SyncRun.Start(); // Initiate the off-load process by auto-clicking the 'OK' button Process[] processes = Process.GetProcessByName ("SYNCMGR"); foreach (Process p in processes) {
IntPtr hWnd = FindWind(p.MainWindowHandle, null); IntPtr hWndChild = FindWindowEx (hWnd, IntPtr.Zero, null, "Sync Mgr"); IntPtr ButtonHandle = FindWindEx (hWndChild, IntPtr.Zero, "Button", null); SendMessage (ButtonHandle, BN_CLICK, WM_LBUTTONDOWN, IntPtr.Zero); SendNessage (ButtonHandle, BN_CLICK, WM_LBUTTONUP, IntPtr.Zero);
}
}
}