在好例子网,分享、交流、成长!
您当前所在位置:首页C# 开发实例Windows系统编程 → C# 进程管理工具实例源码(我爱学习——强制学习)

C# 进程管理工具实例源码(我爱学习——强制学习)

Windows系统编程

下载此实例
  • 开发语言:C#
  • 实例大小:1.23M
  • 下载次数:17
  • 浏览次数:670
  • 发布时间:2017-12-24
  • 实例类别:Windows系统编程
  • 发 布 人:猫九先森
  • 文件格式:.rar
  • 所需积分:5
 相关标签: 学习 强制学习

实例介绍

【实例简介】

添加程序进程名称,检测到进程运行就会关闭该进程,同时开启做题,做题结束后方可运行!关闭程序会在后台继续检测!

程序不会被强制关闭,紧急情况可在进程名内添加我爱学习杀掉自身!

亲测可用

【实例截图】

from clipboard


from clipboard

【核心代码】


using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace 我爱学习
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void HideMainForm()
        {
            this.Hide();
        }

        private void ShowMainForm()
        {
            this.Show();
            this.WindowState = FormWindowState.Normal;
            this.Activate();
        }


#region 窗体关闭时最小化到托盘
        private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = true;
            timer1.Start();
            HideMainForm();
        }
        #endregion
        private void button1_Click(object sender, EventArgs e)
        {
            
            listBox1.Items.Add(comboBox1.Text);
            comboBox1.Focus();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Start();
            comboBox1.Items.Add("QQ");
            comboBox1.Items.Add("hyxd");
        }
        int i = 0;
        //检测进程是否开启
        private void timer1_Tick(object sender, EventArgs e)
        {
            if(listBox1.Items.Count>0)
            {
                if (IsProcessStarted(listBox1.Items[i].ToString()))
                {
                    timer1.Stop();
                    KillProcess(listBox1.Items[i].ToString());
                    MessageBox.Show("系统检测到您当前,打开了"   listBox1.Items[i].ToString()   "请开始做题!中间出错重新开始哦!", "系统提示:");
                    ShowMainForm();
                    timer1.Start();
                    button4.Enabled = true;
                }
                i  ;
                if (i > listBox1.Items.Count || i == listBox1.Items.Count)
                {
                    i = 0;
                }
            }
           
        }
        /// <summary>
        /// 关闭进程
        /// </summary>
        /// <param name="processName">进程名</param>
        private void KillProcess(string processName)
        {
            Process[] myproc = Process.GetProcesses();
            foreach (Process item in myproc)
            {
                if (item.ProcessName == processName)
                {
                    item.Kill();
                }
            }

        }
        /// <summary>

        /// 此函数用于判断某一外部进程是否打开

        /// </summary>

        /// <param name="processName">参数为进程名</param>

        /// <returns>如果打开了,就返回true,没打开,就返回false</returns>

        private bool IsProcessStarted(string processName)

        {

            Process[] temp = Process.GetProcessesByName(processName);

            if (temp.Length > 0) return true;

            else

                return false;

        }
        List<string> key = new List<string>() ;
        //添加进程
        private void button2_Click(object sender, EventArgs e)
        {
            listBox2.Items.Clear();
            string selUrl=null;
            openFileDialog1.Filter = "文本文件|*.txt";//打开文件类型
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {

                selUrl = openFileDialog1.FileName;
                q = 0;


            }
            else return;
            string[] line = File.ReadAllLines(selUrl, Encoding.Default); 
            
            //遍历第10行
            
            //遍历所有行
            for (int i = 0; i < line.Length; i  )
            {
                string str = line[i].ToString();
                try
                {
                    string[] bit = Regex.Split(str, "猫九先森", RegexOptions.IgnoreCase);
                    key.Add(bit[1]);
                    listBox2.Items.Add(bit[0]);
                    progressBar1.Maximum = i;
                }
                catch
                {
                    MessageBox.Show("分隔符有误或者问题含有分隔符!", "系统提示:");
                    return;
                }

            }
            richTextBox1.Text = listBox2.Items[q].ToString();
        }
        int q = 0;


        //导入问题
        private void button4_Click(object sender, EventArgs e)
        {
            q  ;
           
            try
            {
                if (textBox1.Text != "" && textBox1.Text == key[q - 1].ToString())
                {
                    if (q == listBox2.Items.Count)
                    {
                        timer1.Stop();
                        MessageBox.Show("感谢您!现在您可以使用"   listBox1.Items[i].ToString()   "了!", "系统提示:");
                        q = 0;

                    }
                    else
                    {

                        timer1.Start();
                    }
                    richTextBox1.Text = listBox2.Items[q].ToString();
                   

                }
                else
                {
                    q = 0;
                    richTextBox1.Text = listBox2.Items[q].ToString();
                }
                progressBar1.Value = q;
            }
            catch
            {
                MessageBox.Show("系统匹配出现问题!请重新导入问题!" );
            }

            textBox1.Text = "";
            textBox1.Focus();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.Enter&&button4.Enabled ==true )
            {
                q  ;

                try
                {
                    if (textBox1.Text != "" && textBox1.Text == key[q - 1].ToString())
                    {
                        if (q == listBox2.Items.Count)
                        {
                            timer1.Stop();
                            MessageBox.Show("感谢您!现在您可以使用"   listBox1.Items[i].ToString()   "了!", "系统提示:");
                            q = 0;

                        }
                        else
                        {

                            timer1.Start();
                        }
                        richTextBox1.Text = listBox2.Items[q].ToString();


                    }
                    else
                    {
                        q = 0;
                        richTextBox1.Text = listBox2.Items[q].ToString();
                    }
                    progressBar1.Value = q;
                }
                catch
                {
                    MessageBox.Show("系统匹配出现问题!请重新导入问题!");
                }

                textBox1.Text = "";
                textBox1.Focus();
            }
        }

        private void comboBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode==Keys.Enter)
            {
                listBox1.Items.Add(comboBox1.Text);
                comboBox1.Focus();
            }
        }
    }
}


标签: 学习 强制学习

实例下载地址

C# 进程管理工具实例源码(我爱学习——强制学习)

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

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

网友评论

发表评论

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

查看所有0条评论>>

小贴士

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

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

关于好例子网

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

;
报警