title: C# running batch file on remote machine after PsExec has been started
body: <p>Basically, I'm trying to run the batch file that was copied on the remote machine, by the way, this is my first attempt at coding, so please be nice but critique it if you want, I'm still learning the language and had to spend 3 hours to get this far, thank god for Google, LOL.</p>
  
  <p>Code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;
  
  namespace WindowsFormsApplication4
  {
      public partial class Form1 : Form
      {
          public Form1()
          {
              InitializeComponent();
          }
  
          private void cleanerBtn_Click(object sender, EventArgs e)
          {
              //Copying Batch File to Remote Host
              string fileToCopy = "C:\\Clean.bat";
              string newLocation = hostName.Text;
              string newFile = (newLocation + "\\clean.bat");
  
              System.IO.File.Copy(fileToCopy, newLocation);
  
              //Run PsExec
              string psExec = "psexec -s "+newLocation+" cmd";
              System.Diagnostics.Process.Start("CMD.exe", psExec);
  
              //Run Batch File using PsExec
  
  
              //Removing Batch File from Remote Host
              System.IO.File.Delete(newFile);
  
          }
  
      }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>