Exemplo n.º 1
0
        private void buttonExecute_Click(object sender, EventArgs e)
        {
            int    hActiveWindow = WinApi.GetActiveWindow();
            Action action        = (Action)comboBoxActions.SelectedItem;
            Script script        = (Script)action.Script;

            // Execute the script
            if (script != null)
            {
                RunScript(hActiveWindow, script, this);
            }
        }
Exemplo n.º 2
0
        void buttonLaunch_Click(object sender, EventArgs e)
        {
            int hActiveWindow = WinApi.GetActiveWindow();

            // Examine the user's selection and prepare a launch object for execution
            // If the action is a shortcut then add it to the arguments
            // if it is a script, prepare a script object
            Script script = null;

            string arguments = String.Format(
                "-s -h {0}:{1} -v {2} -u {3}", // -C {5} for shortcuts ;; Nacho added -s
                textBoxHost.Text,
                textBoxPort.Text,
                textBoxService.Text,
                textBoxUser.Text);

            // Check for a password in the connection data
            if (textBoxPassword.Text == "")
            {
                arguments = arguments + " -R";  // Recall a saved password
            }
            else
            {
                arguments = arguments + String.Format(" -X {0}", textBoxPassword.Text); // Pass the password explicitly
            }
            // Nacho check Icon tex
            if (textIcon.Text == "")
            {
                arguments = arguments + String.Format(" -P 1,1 ");
            }
            // Nacho
            else
            {
                arguments = arguments + String.Format(" -i {0},0", textIcon.Text); // Pass the icon absolute path
            }
            //arguments = arguments + String.Format(" -P 1,1 ");
            // Check if an action has been selected
            if (comboBoxActions.SelectedIndex != -1)
            {
                if (comboBoxActions.SelectedItem.ToString() != "")
                {
                    Action action = (Action)comboBoxActions.SelectedItem;

                    // Check for shortcuts
                    if (action.Shortcut != null)
                    {
                        arguments = arguments + String.Format(" -C {0}", action.Shortcut);
                    }

                    // Check for scripts
                    if (action.Script != null)
                    {
                        script = (Script)action.Script;
                    }
                }
            }

            // Execute the program with the given arguments
            panel1.Text = "Launching connection...";
            try
            {
                System.Diagnostics.Process process;

                if (script == null && numericSessions.Value > 1)
                {
                    // Launch multiple sessions if no script selected and sessions is greater than one
                    for (int iCount = 1; iCount <= numericSessions.Value; iCount++)
                    {
                        process = System.Diagnostics.Process.Start(textBoxPath.Text, arguments);
                    }
                }
                else
                {
                    process = System.Diagnostics.Process.Start(textBoxPath.Text, arguments);
                }

                // Minimize the window
                if (Convert.ToBoolean(ConfigurationManager.AppSettings["MinimizeOnLaunch"]) == true)
                {
                    WindowState = FormWindowState.Minimized;
                }

                // Execute the script if selected
                if (script != null)
                {
                    RunScript(hActiveWindow, script, this);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(String.Format("Error in connection data:\n\n{0}.\n\nPlease check the KClient path and try again.", ex.Message), "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // Reset status bar message
            panel1.Text = "Select a connection...";
        }