Пример #1
0
        /**
         * 获得电脑的基本信息
         * */
        private void Btn_Get_Info(object sender, RoutedEventArgs e)
        {
            GetInfo getInfo = new GetInfo();
            string  Ip      = getInfo.GetIpInfo();
            string  Mac     = getInfo.GetMacInfo();
            Dictionary <int, string> process = getInfo.GetProcessInfo();

            this.IpBox.Text  = Ip;
            this.MacBox.Text = Mac;
        }
Пример #2
0
        /**
         * 设置托盘
         * */
        private void InitialTray()
        {
            // 获得电脑信息
            GetInfo getInfo = new GetInfo();
            string  Ip      = getInfo.GetIpInfo();
            string  Mac     = getInfo.GetMacInfo();
            Dictionary <int, string> process = getInfo.GetProcessInfo();

            //设置托盘的各个属性
            notifyIcon = new System.Windows.Forms.NotifyIcon();
            // 设置托盘图标
            notifyIcon.Icon = new System.Drawing.Icon(System.Windows.Forms.Application.StartupPath + "\\computer.ico");
            // 是否显示图标
            notifyIcon.Visible = true;

            //设置菜单项
            // System.Windows.Forms.MenuItem SetUp = new System.Windows.Forms.MenuItem("设置");
            // 鼠标点击设置 显示主窗体
            // SetUp.Click += Show_MainWindows;

            // 显示电脑IP菜单项
            System.Windows.Forms.MenuItem IP = new System.Windows.Forms.MenuItem(Ip);

            //退出菜单项
            System.Windows.Forms.MenuItem exit = new System.Windows.Forms.MenuItem("退出");
            // 退出按钮--退出输入密码
            exit.Click += Exit_Click;

            //关联托盘控件
            System.Windows.Forms.MenuItem[] childen = new System.Windows.Forms.MenuItem[] { IP, exit };
            notifyIcon.ContextMenu = new System.Windows.Forms.ContextMenu(childen);

            // 链接服务器
            connect_socket();
            // 第一次链接发送信息
            sent_msg(Ip, Mac);
            Thread.Sleep(1000 * 2);
            // 发送进程
            sent_process(process);
        }
Пример #3
0
        /**
         * 功能描述:向服务器端发送消息以及心跳包
         * */
        private void SendMsg_Click(object sender, RoutedEventArgs e)
        {
            // 获得信息进行发送
            GetInfo getInfo = new GetInfo();
            string  Ip      = getInfo.GetIpInfo();
            string  Mac     = getInfo.GetMacInfo();

            Hashtable ht = new Hashtable();

            ht.Add("ip", Ip);
            ht.Add("mac", Mac);
            ht.Add("command", "Heartbeat");

            JavaScriptSerializer js = new JavaScriptSerializer();
            string sendJs           = js.Serialize(ht);
            string sendStr          = sendJs.ToString();

            // Send Message
            tcInt.SentMsg(sendStr);
            Thread.Sleep(1000 * 2);
            // 开始心跳线程
            tcInt.Start();
        }