RemoteHelper V1.0 远程关机助手源代码放出

  某天上课的时候,老湿说了下利用微薄关电脑的功能,自己从实用性,原理性,实现性,待加强四个方面进行了对比。

  一,实用性

  1.使用场景:一般情况下,好像使用软件都是在下载未完成的情况下使用的,其实有下载并关机的功能的软件,有太多了,比如,讯雷的

又比如115网盘的下载关机功能

其实内置下载关机的功能相当多。反而单独将远程关机这个功能拿出来的很少很少

2.原理性:

手机发出特征信息1)——>软件收到特征信息2)——>软件执行关机功能3)

RemoteHelper V1.0 直接利用正则表达式真是感叹,正则表达式功能何其的强大!),执行步骤2),然后执行功能3)

3.实现性:

源代码分析:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Runtime.InteropServices;
using System.Management;
using System.Diagnostics;
using System.Net;
using System.Text.RegularExpressions;
using System.IO;
using System.Timers;
using System.Threading;

namespace Test1
{
    public partial class FrmMain : Form
    {
        public FrmMain)
        {
            InitializeComponent);
            Control.CheckForIllegalCrossThreadCalls = false;
        }
        [DllImport"user32.dll", EntryPoint = "ExitWindowsEx", CharSet = CharSet.Ansi)]
        private static extern int ExitWindowsExint uFlags, int dwReserved);
        //定义为全局变量

        //记录list的索引
        int x = -1;
        //定义全局的内容
        List<string> list = new List<string>);
        Thread thGet;
        
        private void button1_Clickobject sender, EventArgs e)
        {
            //重新设定索引序列的值
            x = -1;
            //将lbState的值重新清空
            lbState.Items.Clear);
            //添加当前状态
            lbState.Items.Add"线程初使化,执行监听...");
            btnStart.Enabled = false;
            btnCancel.Enabled = true;
            
            thGet = new ThreadOffByNet);
            //如果不设置都所有线程都是前台,在前台闭后然后执行关
            thGet.IsBackground = true;
            thGet.StarttxtUrl.Text.Trim));
           
        }
        private void btnCancel_Clickobject sender, EventArgs e)
        {
            btnStart.Enabled = true;
            btnCancel.Enabled = false;
            if thGet!=null)
            {
                thGet.Abort);
            }
            
        }
        //执行关机方法
        #region 关机
        void shutdown)
        {
            Process myProcess = new System.Diagnostics.Process);
            myProcess.StartInfo.FileName = "cmd.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.RedirectStandardInput = true;
            myProcess.StartInfo.RedirectStandardOutput = true;
            myProcess.StartInfo.RedirectStandardError = true;
            myProcess.StartInfo.CreateNoWindow = true;
            myProcess.Start);
            myProcess.StandardInput.WriteLine"shutdown -s -t 60");
        }
        #endregion
      
        //获取网页
        private void GetContentstring url)
        {                           
                StringBuilder sb = new StringBuilder);
                WebRequest wr = WebRequest.Createurl);
                WebResponse wre = wr.GetResponse);
                using Stream str = wre.GetResponseStream))
                {
                    StreamReader sr = new StreamReaderstr, Encoding.Default);
                    string line;
                    while line = sr.ReadLine)) != null)
                    {
                        sb.Appendline);
                    }

                }
                list.Addsb.ToString));                      
        }
        //反应状态
        private bool CommandResultstring content, string command)
        {
            
            bool result = false;
            Match ma = Regex.Matchcontent, command);
            if ma.Success)
            {
                result = true;
            }
            return result;
        }      
        //读文本关机
        private void GetBytxt)
        {                     
            while true)
            {
                
                Thread.Sleep2000);
                x++;
                string content = File.ReadAllText"1.txt", Encoding.Default);
                list.Addcontent);
                bool b = CommandResultlist[x], txtCommand.Text.Trim));
                if b==true)
                {
                    shutdown);
                }
            }
            
        }
        //读网络关机
        private void OffByNetobject ur)
        {
            string url = ur as string;
            while true)
            {
                Thread.Sleep2000);
                x++;
                GetContenturl);
                bool result = CommandResultlist[x], txtCommand.Text.Trim));
                if result==true)
                {
                    lbState.Items.Clear);
                    lbState.Items.Add"捕获命令,执行关机");                   
                    shutdown);
                    thGet.Abort);
                }
                else
                {
                    lbState.Items.Add"正在监听中,请等待.......");
                }
            }
        }

        private void FrmMain_FormClosingobject sender, FormClosingEventArgs e)
        {
            DialogResult dr = MessageBox.Show"是否取消当前监听?","监听",MessageBoxButtons.YesNo,MessageBoxIcon.Warning);
            if dr !=System.Windows.Forms.DialogResult.Yes)
            {
                e.Cancel = true;
            }
        }

        private void FrmMain_Loadobject sender, EventArgs e)
        {

        }

       
    }
}

 4.不足性

微薄关机,监控软件始终需要一个公共的参看微薄的功能,软件在写的时候一直没有解决这个”公共的查看微薄”的功能,如果不登录,本身是没有查看的功能。思来想去,要么微薄提供一个公共的API,要不然就用其它的方式,想了半天还是没有想出解决方法,今天在cnblogs看到一位朋友说了解决方法:

注册一个公共的微薄账号,然后关注需要监控的微薄,将公共微薄内置在监控软件内可是如何实现软件模拟登陆呢?),然后就可以实现远程关机功能

小弟初学C#,欢迎各位大神拍砖

Published by

风君子

独自遨游何稽首 揭天掀地慰生平

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注