How to Execute Process on Remote Machine, in C#

Execute C# code on remote machine

for getting list of process on remote machine just enter name of remote machine in brackests..

      Process[] processlist = Process.GetProcesses(Remotemachine);

for reference:
https://msdn.microsoft.com/en-us/library/1f3ys1f9%28v=vs.110%29.aspx

Execute exe on remote machine

The answer was a combination from your replies. But the whole correct solution was:

        ProcessStartInfo info = new ProcessStartInfo("C:\\PsTools");
info.FileName = @"C:\PsTools\psexec.exe";
info.Arguments = @"\\" + serverName + @" -i C:\WINDOWS\notepad.exe";
info.RedirectStandardOutput = true;
info.UseShellExecute = false;
Process p = Process.Start(info);

execute command on remote machine

You need to use the Win32_Process class.

Here's an example of its use: http://msdn.microsoft.com/en-us/library/ms257364(v=vs.80).aspx

Example:

ManagementClass processClass = new ManagementClass(@"\\<remotecomputername>\root\cimv2:Win32_Process");
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");

inParams["CommandLine"] = "calc.exe";
inParams["CurrentDirectory"] = @"c:\windows\system32";

ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);


Related Topics



Leave a reply



Submit