c# - 如何在远程机器上执行进程,在 C# 中

标签 c# process system.diagnostics

如何使用 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/

相关文章:

c# - ASP.NET MVC 查看另一个 Controller 的 ExecuteResult

c# - 如何调用启用 SSL 的 Web Api?

c# - XML 序列化 - 为什么我不能更改编码?

c# - 从 C# 运行时命令行进程不工作

c# - User3 2's ShowWindow doesn' t 按预期行事

c# - 为什么 null == myVar 而不是 myVar == null?

android - 如何防止系统杀死我的 'foreground' 服务?

c# - 确定应用程序从哪个位置启动

c# - WPF 使用 .Net 3.1 - Process.Start Excel 文件错误 : "The specified executable is not a valid application for this OS platform."

c# - DefaultTraceListener 的性能影响