尝试使用 psexec (c#) 在远程运行 .exe 时出现问题?
嘿大家, 我正在尝试在远程计算机上运行 exe 文件(不是从远程计算机,而是在远程计算机上)。
我有非常简单的代码如下:
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);
当尝试运行此代码时,我收到“系统找不到指定的文件”错误。
- 指定目录中有一个名为“test.bat”的文件。
- 远程计算机位于同一域中,并且 C 文件夹是共享的(我是管理员)。
- 我已安装 PsTools 并将其配置为环境变量。
- 我尝试了各种代码(例如,如果我不在 ProcessStartInfo 构造函数和 FileName 属性上使用“psexec”,bat 文件将在本地计算机而不是远程计算机上运行...),但没有任何效果!
有什么想法吗?
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.
- There is a file named "test.bat" on the specified directory.
- The remote machine is on the same domain and the C folder is shared (I'm the admin).
- I have PsTools installed and configured as environment variables.
- 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的猜测是它找不到
psexec
,因为您已将 UseShellExecute 设置为 false。尝试提供 psexec.exe 的完整路径。您还应该将
FileName
属性设置为just您要启动的文件,并将Arguments
属性设置为命令行参数,如下所示:请注意,我还在
Arguments
属性中添加了双引号,这样它就不会因为“Program Files”中包含空格而被分成两个参数。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 theArguments
property to the command line arguments, like this: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.