I have remote server name(windows), usernameand password.
Using C # .Net, I want run a commandon a remote server and return console output
Is there any way to do this in C #?
I managed to run the command using the WMIfollowing code (partial), but without the knowledge of the console output. I could only return Process ID.
ObjectGetOptions objectGetOptions = new ObjectGetOptions();
ManagementPath managementPath = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(scope, managementPath,objectGetOptions);
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
inParams["CommandLine"] = "cmd.exe /c "+ mycommand;
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
Any ideas?
source
share