コード例 #1
0
ファイル: Arguments.cs プロジェクト: karthikfbk/WinRM-Execute
        /// <summary>
        /// Event to trigger on click of 'Run' button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            DialogResult result;
            if (!ValidateArgumentValues())
            {
                result = MessageBox.Show("Empty Argument Values ", "Error ARGS_VALUES", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string FinalCommand = MyCommand.GetFinalCommand(VariableArgs);

            if (FinalCommand.Equals(string.Empty))
            {
                result = MessageBox.Show("Error deriving final WinRM Command ", "Error FINAL_COMMAND", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {

                string output = string.Empty;
                string error = string.Empty;

                ProcessStartInfo processStartInfo = new ProcessStartInfo("cmd", "/c "+FinalCommand);
                processStartInfo.RedirectStandardOutput = true;
                processStartInfo.RedirectStandardError = true;
                processStartInfo.WindowStyle = ProcessWindowStyle.Minimized;
                processStartInfo.CreateNoWindow = true;
                processStartInfo.UseShellExecute = false;

                Process process = Process.Start(processStartInfo);
                Loading load = new Loading();
                load.Show();
                load.Refresh();
                using (StreamReader streamReader = process.StandardOutput)
                {
                    output = streamReader.ReadToEnd();
                }

                using (StreamReader streamReader = process.StandardError)
                {
                    error = streamReader.ReadToEnd();
                }

                if (!string.IsNullOrEmpty(output))
                    WriteToOutputFile(output);
                else
                    WriteToOutputFile(error);

                MyCommand.UpdateArgValues(VariableArgs);
                load.Close();

                Display form5 = new Display();
                form5.ShowDialog();
            }
        }
コード例 #2
0
ファイル: Home.cs プロジェクト: karthikfbk/WinRM-Execute
 private void button5_Click(object sender, EventArgs e)
 {
     DialogResult result = this.openFileDialog1.ShowDialog(); // Show the dialog.
     if (result == DialogResult.OK) // Test result.
     {
         string file = openFileDialog1.FileName;
         if (!string.IsNullOrEmpty(file))
         {
             Display form = new Display(file);
             form.Show();
         }
     }
 }