如何在C#中在远程计算机上执行进程 [英] How to execute process on remote machine, in C#
本文介绍了如何在C#中在远程计算机上执行进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何使用System.Diagnostics.Process类在C#中的远程计算机上启动一个进程,说计算机名= someComputer?
How can I start a process on a remote computer in c#, say computer name = "someComputer", using System.Diagnostics.Process class?
我创建了一个远程计算机上的小型控制台应用程序,它只是将 Hello world写入txt文件,我想远程调用它。
I created a small console app on that remote computer that just writes "Hello world" to a txt file, and I would like to call it remotely.
控制台应用程序路径:c:\ AppMyAppFolder\MyApp.exe
Console app path: 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);
我不断收到找不到网络路径。
I keep getting "Network path was not found".
推荐答案
可以从 http:// technet使用PsExec。 microsoft.com/en-us/sysinternals/bb897553.aspx
或WMI:
object theProcessToRun() = { "YourFileHere" };
ManagementClass theClass = new ManagementClass(@"\\server\root\cimv2:Win32_Process");
theClass.InvokeMethod("Create", theProcessToRun);
这篇关于如何在C#中在远程计算机上执行进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文