-1

I am trying to execute a command on "psexec" by passing some variable to it. Tried various ways to execute it but still not able to accomplish it.

I want to execute following with button event handler.

private void button3_Click(object sender, EventArgs e)
    {
        System.Diagnostics.Process proc = new System.Diagnostics.Process();
        proc.EnableRaisingEvents = false;
        proc.StartInfo.FileName = "psexec.exe"; //currently its in debug folder
        proc.StartInfo.Arguments = "/c \\10.10.1.10 -u domain\test1 -p testpass " + "C:\\windows\\system32\\cmd.exe";
        proc.Start();

       // proc.WaitForExit();
        MessageBox.Show("Command Exected");


    }
Amrit Sharma
  • 1,906
  • 8
  • 45
  • 75
  • 2
    Escape what you pass to .Arguments or `@"/c \\10...` – Alex K. Oct 21 '14 at 11:51
  • I have tried that already, but doesn't make difference. – Amrit Sharma Oct 21 '14 at 11:56
  • It should make a world of difference. The first part of the string only compiles because it happens to include a `t` after the third backslash. But it means that you're sending "domain" + [tab character] + "est1". I assume that makes a difference to your call. – DonBoitnott Oct 21 '14 at 13:49
  • Why someone like to down vote a genuine question. Moderator should banned those users.. – Amrit Sharma Oct 22 '14 at 00:47

1 Answers1

0

I don't know C# well, but here's working code I use to do a very similar thing in VB.NET:

    Private Sub startProcess(ByVal remotePC As String, ByVal remotePC_URL As String, ByVal remoteUser As String, ByVal password As String)
    Dim proc As New System.Diagnostics.Process
    proc.StartInfo = New ProcessStartInfo("CMD")
    proc.StartInfo.Arguments = "/k psexec \\" & remotePC & " -u " & remoteUser & " -p " & password & " -i -d ""C:\Program Files (x86)\Internet Explorer\iexplore.exe"" -k " & remotePC_URL & ""
    proc.StartInfo.CreateNoWindow = True
    proc.StartInfo.UseShellExecute = False
    proc.Start()
End Sub 'startProcess
Oryx
  • 302
  • 9
  • 21