如何在远程机器上执行进程,在 C# 中 [英] How to execute process on remote machine, in C#

查看:19
本文介绍了如何在远程机器上执行进程,在 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:MyAppFolderMyApp.exe

Console app path: c:MyAppFolderMyApp.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.microsoft.com/en-us/sysinternals/bb897553.aspx

或 WMI:

object theProcessToRun() = { "YourFileHere" };

ManagementClass theClass = new ManagementClass(@"\server
ootcimv2:Win32_Process");

theClass.InvokeMethod("Create", theProcessToRun);

这篇关于如何在远程机器上执行进程,在 C# 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆