使用C#检查进程是否在远程系统上运行

9 .net c# system.diagnostics

我试图检查进程是否在远程系统上运行.我使用以下代码:

string procSearc = "notepad";
string remoteSystem = "remoteSystemName";

Process[] proce = System.Diagnostics.Process.GetProcessesByName(procSearch, remoteSystem);
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试运行代码时,我收到以下错误:"无法连接到远程计算机."

我可以使用以下命令运行pslist:C:> pslist\remoteSystemName所以我知道可以获取我需要的信息,但我需要在代码中.

另一种可能性是将pslist集成到C#中并搜索列表以查看该进程是否存在,但我还没有找到有关如何执行此操作的信息.

Lar*_*ipp 8

使用System.ServiceProcess.ServiceController该类进行服务.您可以使用Status,以检查它是否运行,Stop()Start()对其进行控制.

ServiceController sc = new ServiceController();
sc.MachineName = remoteSystem;
sc.ServiceName = procSearc;

if (sc.Status.Equals(ServiceControllerStatus.Running))
{
   sc.Stop();
}
else
{
   sc.Start();
}
Run Code Online (Sandbox Code Playgroud)