0

i want to run pstool from windows form. i tried the code:

                System.Diagnostics.Process process = new System.Diagnostics.Process();
                System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
                startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
                startInfo.FileName = "cmd.exe";
                startInfo.Arguments = @"C:\\PSTools\\PsExec.exe \\\\" + dnsName+" CMD";
                process.StartInfo = startInfo;
                process.Start();

but it open the command lint and not running the command:"C:\PSTools\PsExec.exe \\" + dnsName+" CMD"

what am i doing wrong?

Doron nuni
  • 23
  • 6
  • you're tell it to run `cmd.exe`, and trying to get cmd to execute a command. Try executing just the program you want, or changing the cmd arguments to include `/k`. – BurnsBA Apr 14 '17 at 14:16
  • the command to run the pstool is:"c:\pstool.exe \\ip cmd" how to write it on the argument? – Doron nuni Apr 14 '17 at 14:20
  • ok it's working. i add /k to argument. startInfo.Arguments = @"C:\\PSTools\\PsExec.exe \\\\" + dnsName+" CMD"; – Doron nuni Apr 14 '17 at 14:26

1 Answers1

0

You can directly executed PsExec by setting it's exe into FileName. The arguments that are accepted by PsExec can go in the Arguments property, like so:

startInfo.FileName = @"C:\PSTools\PsExec.exe";
startInfo.Arguments = String.Format(@"\\{0} CMD", dnsName);

Keep in mind that once you indicated with @ that you're after a verbatim string you no longer need to escape your back-slashes.

Community
  • 1
  • 1
rene
  • 41,474
  • 78
  • 114
  • 152