您的位置:首页 > 编程语言 > C#

关于C#远程执行命令后,在远程主机上能看到进程但看不到交互窗口的问题(一)

2013-08-28 14:46 501 查看
 
  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.csdn.net/ibet1224/article/details/10447059
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐