开发者

Problem while trying to run .exe on remote with psexec (c#)?

Hey all, I'm trying to run an exe file ON A REMOTE MACHINE (not from, but ON).

I have very simple code as following:

ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
info.FileName = "psexec \\\\" + machine.Name + "\\C\\Program Files\\test.exe";
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);

When trying to run this code i get "The system cannot find the file specified" error.

  1. There is a file named "test.bat" on the specified directory.
  2. The remote machine is on the same domain and the C folder is shared (I'm the admin).
  3. I have PsTools installed and configured as environment variables.
  4. I have tried variety of codes (for example if i don't use "psexec" on the ProcessStartInfo constructor and on the FileName property, 开发者_运维百科the bat file runs on the local machine instead of the remote one...) and nothing works!

any ideas?


My guess is that it's failing to find psexec, because you've set UseShellExecute to false. Try giving the full path to psexec.exe.

You should also set the FileName property to just the file you want to start, and the Arguments property to the command line arguments, like this:

ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
info.FileName = @"c:\whatever\psexec.exe";
info.Arguments = @"""\\" + machine.Name + @"\C\Program Files\test.exe""";
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);

Note that I've also added double quotes in the Arguments property so that it doesn't get split into two arguments due to "Program Files" having a space in it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜