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.
- On the target machine, run
dcomcnfg
from the command prompt.
- Expand
Component ServicesComputersMy ComputerDCOM Config
- Find Windows Management Instruction, identified with GUID
8BC3F05E-D86B-11D0-A075-00C04FB68820
(you can see this in the details view).
- Edit the properties and then add the username you are trying to login with under the permissions tab.
- You may need to reboot the service or the entire machine.
NOTE: All paths used for the remote process need to be local to the target machine.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…