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
Unit Test a Method That Returns a Void
Clearing a Textbox Leaves an Invisible Character
How to Convert HTML to Pdf Using Itextsharp
Regex to Match Alphanumeric and Spaces
How to Refresh an Entity Framework Core Dbcontext
Get Properties and Values from Unknown Object
Convert from Httpresponsemessage to Iactionresult in .Net Core
How to Show Alert Message in MVC 4 Controller
Add Spaces Before Capital Letters
C# How to Simply Encrypt a Text File With a Pgp Public Key
Newtonsoft Json Dynamic Property Name
Could Not Parse the Json File ,Error in Progam.Cs ASP.NET Core
C# Linq Using Null or Empty Strings in a Where Statment
How to Redirect to Login Page If Session Is Not Available in MVC