private void button2_Click(object sender, EventArgs e)
{
ConnectionOptions opt = new ConnectionOptions();
opt.Username = textBox4.Text;
opt.Password = textBox5.Text;
ManagementScope scope = new ManagementScope("\\\\" + textBox3.Text + "\\root\\cimv2", opt);
Debug.WriteLine("ManagementScope create success!" + scope.ToString());
scope.Connect();
ObjectGetOptions o = new ObjectGetOptions();
ManagementPath path = new ManagementPath("Win32_Process");
ManagementClass processClass = new ManagementClass(scope, path, o);
Debug.WriteLine("ManagementClass create success!");
ManagementBaseObject inParams = processClass.GetMethodParameters("Create");
// inParams["CommandLine"] = textBox2.Text;
inParams["CommandLine"] = "calc.exe";
ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null);
Debug.WriteLine("command has been sent!" + outParams.GetText(TextFormat.Mof));
}
以上代码执行后能在远程主机的任务管理看到calc.exe,但看不到计算器界面.
限于局域网上传流量,接下内容见
http://blog.youkuaiyun.com/ibet1224/article/details/10447059