C# C中的外部进程执行参数问题#
我试图使用C# C中的外部进程执行参数问题#,c#,.net,C#,.net,我试图使用PsExec从C#console应用程序向RDP连接发送命令,这是命令 PsExec.exe //1.2.3.4 -u administrator -p secredpassword -c RemoteAppExe.exe wich工作正常,在该系统上运行RemoteAppExe.exe,问题是在C#中它不工作,下面是我的代码: System.Diagnostics.Process pProcess = new System.Diagnostics.Process(); pProce
PsExec
从C#console应用程序向RDP连接发送命令,这是命令
PsExec.exe //1.2.3.4 -u administrator -p secredpassword -c RemoteAppExe.exe
wich工作正常,在该系统上运行RemoteAppExe.exe
,问题是在C#中它不工作,下面是我的代码:
System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
pProcess.StartInfo.FileName = @"PsExec.exe";
pProcess.StartInfo.Arguments = "//1.2.3.4 -u administrator -p secredpassword -c RemoteAppExe.exe"; //argument
pProcess.StartInfo.UseShellExecute = false;
pProcess.StartInfo.RedirectStandardOutput = true;
pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
pProcess.StartInfo.CreateNoWindow = true; //not diplay a windows
pProcess.Start();
string output = pProcess.StandardOutput.ReadToEnd(); //The output result
pProcess.WaitForExit();
有什么问题?我想这可能是因为没有正确地转义参数
有什么想法吗
谢谢。应该是:
pProcess.StartInfo.Arguments = @"\\1.2.3.4 -u administrator -p secredpassword -c RemoteAppExe.exe";
更改参数行使代码适合我。应该是:
pProcess.StartInfo.Arguments = @"\\1.2.3.4 -u administrator -p secredpassword -c RemoteAppExe.exe";
更改参数行使代码对我有效。可以从任何文件夹执行
psexec.exe
?或者只是从一个特定的?如果是,请尝试从任何目录添加pProcess.StartInfo.WorkingDirectory
。我尝试了'pProcess.StartInfo.WorkingDirectory=“.”;`,没有结果,它只是向我显示帮助,好像我运行它时没有参数,或者参数无效。。。怎么办?我还用PHP
和EXEC
制作了一个脚本,它工作得很好。。。为什么不呢?问题是什么?您是否尝试在没有隐藏窗口的所有行的情况下运行它?仅使用filename和arguments参数?或者可能与行政权有关。尝试使用管理权限运行Visual Studio。我从CMD运行它,它只是忽略参数,我以管理员身份运行CMD,我正常运行命令,它工作,唯一不工作的是C#…可以从任何文件夹执行psexec.exe
?或者只是从一个特定的?如果是,请尝试从任何目录添加pProcess.StartInfo.WorkingDirectory
。我尝试了'pProcess.StartInfo.WorkingDirectory=“.”;`,没有结果,它只是向我显示帮助,好像我运行它时没有参数,或者参数无效。。。怎么办?我还用PHP
和EXEC
制作了一个脚本,它工作得很好。。。为什么不呢?问题是什么?您是否尝试在没有隐藏窗口的所有行的情况下运行它?仅使用filename和arguments参数?或者可能与行政权有关。尝试运行具有管理权限的Visual Studio。我从CMD运行它,它只是忽略参数,我以管理员身份运行CMD,我正常运行命令,它工作,唯一不工作的是C#…dosent工作,我尝试了@“\\\…
和@/..
,只是打印帮助,就像我在没有任何参数的情况下运行一样……我还将PsExec.exe
从System32
移动到另一个文件夹,因为当PsExec.exe
位于System32
中时,程序抛出了一个未找到该exe的异常。我还为RemoteAppExe.exe
输入了完整路径。在工作中,我尝试了@“\\..
和@”//..
,只是打印帮助,就好像我在没有任何参数的情况下运行一样……我还将PsExec.exe
从System32
移动到了另一个文件夹,因为当PsExec.exe
在System32
中时,程序抛出了一个未找到该exe的异常。我还输入了RemoteAppExe.exe
的完整路径。