DJP*_*JPB 13 c# system.diagnostics process
如何使用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);
Run Code Online (Sandbox Code Playgroud)
我一直在"找不到网络路径".
Iva*_* G. 16
可以使用来自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);
Run Code Online (Sandbox Code Playgroud)
Sev*_*yev 14
使用以下之一:
或者,如果您愿意,请注入您自己的服务或COM组件.这与PsExec的作用非常接近.
在所有这些方法中,我更喜欢任务调度程序.我认为,这些都是最干净的API.连接到远程任务调度程序,为可执行文件创建新任务,运行它.注意:可执行文件名应该是该计算机的本地名称.不是\ servername\path\file.exe,而是c:\ path\file.exe.如果您愿意,请删除该任务.
所有这些方法都要求您具有对目标计算机的管理访问权限.
ProcessStartInfo
无法启动远程进程.