I have a shared folder in a server and I need to remotely execute a command on some files. How do I do that?
What services need to be running on the server to make that work?
Some details: Only C# can be used. Nothing can be installed in the server.
Step 1. Open Command Prompt, then type in “mstsc” and press Enter to evoke the Windows Remote Desktop. Step 2. Enter the Computer and User name of the remote computer to remotely control it.
The remote system's MAC address is the last entry in the output from the command. An alternative to the above is to use the psexec tool from Mark Russinovich's Windows Sysinternals suite of tools. Using psexec, you can run ipconfig /all remotely on the remote machine and return the result to your local computer.
Another solution is to use WMI.NET or Windows Management Instrumentation.
Using the .NET Framework namespace System.Management, you can automate administrative tasks using Windows Management Instrumentation (WMI).
Code Sample
using System.Management; ... var processToRun = new[] { "notepad.exe" }; var connection = new ConnectionOptions(); connection.Username = "username"; connection.Password = "password"; var wmiScope = new ManagementScope(String.Format("\\\\{0}\\root\\cimv2", REMOTE_COMPUTER_NAME), connection); var wmiProcess = new ManagementClass(wmiScope, new ManagementPath("Win32_Process"), new ObjectGetOptions()); wmiProcess.InvokeMethod("Create", processToRun);
If you have trouble with authentication, then check the DCOM configuration.
dcomcnfg
from the command prompt. Component Services\Computers\My Computer\DCOM Config
8BC3F05E-D86B-11D0-A075-00C04FB68820
(you can see this in the details view).NOTE: All paths used for the remote process need to be local to the target machine.
You could use SysInternal's PsExec.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With