如何使用 System.Diagnostics.Process 类在 C# 中的远程计算机上启动进程,例如计算机名称 =“someComputer”?
我在那台远程计算机上创建了一个小型控制台应用程序,它只是将“Hello world”写入一个 txt 文件,我想远程调用它。
控制台应用程序路径:c:\MyAppFolder\MyApp.exe
目前我有这个:
ProcessStartInfo startInfo = new ProcessStartInfo(string.Format(@"\\{0}\{1}", someComputer, somePath);
startInfo.UserName = "MyUserName";
SecureString sec = new SecureString();
string pwd = "MyPassword";
foreach (char item in pwd)
{
sec.AppendChar(item);
}
sec.MakeReadOnly();
startInfo.Password = sec;
startInfo.UseShellExecute = false;
Process.Start(startInfo);
我不断收到“找不到网络路径”的提示。
最佳答案
可以使用来自 http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx 的 PsExec
或 WMI:
object theProcessToRun() = { "YourFileHere" };
ManagementClass theClass = new ManagementClass(@"\\server\root\cimv2:Win32_Process");
theClass.InvokeMethod("Create", theProcessToRun);
关于c# - 如何在远程机器上执行进程,在 C# 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2343677/