public void BringWindowToForeground()
 {
     if (MainWindowHandle != IntPtr.Zero)
     {
         RobotWin32.SetForegroundWindow(MainWindowHandle);
     }
 }
        public void Execute(Arguments arguments)
        {
            string errorJump = arguments.ErrorJump != null && arguments.ErrorJump != null?arguments.ErrorJump.ToString() : string.Empty;

            string host = arguments.Host.Value;

            //telnet = System.Diagnostics.Process.Start(pathToTelnet, host);
            putty = System.Diagnostics.Process.Start(pathToPutty, "-load AS400");
            System.Threading.Thread.Sleep(2000);
            //RobotWin32.ShowWindow(telnet.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal);
            //IntPtr iHandle = RobotWin32.FindWindow(null, telnet.MainWindowTitle);
            RobotWin32.ShowWindow(putty.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal);
            IntPtr iHandle = RobotWin32.FindWindow(null, putty.MainWindowTitle);

            RobotWin32.SetForegroundWindow(iHandle);
        }
        public void Execute(Arguments arguments)
        {
            var pathToTelnet = Path.Combine(AbstractSettingsContainer.Instance.UserDocsAddonFolder.FullName, @"telnet.exe");
            var pathToPutty  = Path.Combine(AbstractSettingsContainer.Instance.UserDocsAddonFolder.FullName, @"putty.exe");
            var errorJump    = arguments.ErrorJump != null && arguments.ErrorJump != null?arguments.ErrorJump.ToString() : string.Empty;

            var host = arguments.Host.Value;
            //telnet = System.Diagnostics.Process.Start(pathToTelnet, host);
            var putty = Process.Start(pathToPutty, "-load AS400");

            Thread.Sleep(2000);
            //RobotWin32.ShowWindow(telnet.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal);
            //IntPtr iHandle = RobotWin32.FindWindow(null, telnet.MainWindowTitle);
            RobotWin32.ShowWindow(putty.MainWindowHandle, RobotWin32.ShowWindowEnum.ShowNormal);
            var iHandle = RobotWin32.FindWindow(null, putty.MainWindowTitle);

            RobotWin32.SetForegroundWindow(iHandle);
        }
        private void ExecuteCode(AccessFormModel formModel, AccessControlModel control, string code)
        {
            if (code == "[Event Procedure]")
            {
                //form.SetFocus();
                control.SetFocus();

                RobotWin32.SetForegroundWindow((IntPtr)formModel.Hwnd);
                System.Windows.Forms.SendKeys.SendWait("{ENTER}");
            }
            else if (!string.IsNullOrEmpty(code))
            {
                application.DoCmd.RunMacro(code);
            }
            else
            {
                throw new Exception("Code to execute is empty");
            }
        }