ConnectionOptions options = new ConnectionOptions();
options.Username = "administrator";//登陆远程计算机用户名称
options.Password = "password";//远程计算机用户密码
ManagementScope scope = new ManagementScope("" + "#.#.#.#" + "//root//cimv2", options);
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process ");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
System.Data.DataTable result = new System.Data.DataTable();
result.Columns.Add("Name", Type.GetType("System.String"));
result.Columns.Add("ProcessId", Type.GetType("System.Int32"));
result.Columns.Add("Caption", Type.GetType("System.String"));
result.Columns.Add("Path", Type.GetType("System.String"));
foreach (ManagementObject m in queryCollection)
{
DataRow row = result.NewRow();
row["Name"] = m["Name"].ToString();
row["ProcessId"] = Convert.ToInt32(m["ProcessId"]);
if (m["Caption"] != null) row["Caption"] = m["Caption"].ToString();
if (m["ExecutablePath"] != null) row["Path"] = m["ExecutablePath"].ToString();
result.Rows.Add(row);
}