using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace FindProcess
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
System.Diagnostics.Process[] pro = System.Diagnostics.Process.GetProcesses();
foreach (System.Diagnostics.Process IsProcedding in pro)
{
this.listBox1.Items.Add(IsProcedding.ProcessName.ToString());
}
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
System.Diagnostics.Process[] pro1 = System.Diagnostics.Process.GetProcesses();
bool find ;
foreach (System.Diagnostics.Process IsProcedding in pro1)
{
find = false;
for (int i = 0; i <= this.listBox1.Items.Count-1; i++)
{
if (this.listBox1.Items[i].ToString() == IsProcedding.ProcessName.ToString())
{
find = true;
}
}
if (find == false)
{
System.DateTime currentTime = new System.DateTime();
currentTime = System.DateTime.Now;
this.listBox2.Items.Add("进程名:"+IsProcedding.ProcessName.ToString()+"--启动时间:"+currentTime.ToString());
this.listBox1.Items.Add(IsProcedding.ProcessName.ToString());
}
}
}
}
}
谢谢楼主!
课程设计还差这部分功能就完成了!
想了一下把楼主的程序改成:
System.DateTime currentTime = new System.DateTime();
currentTime = System.DateTime.Now;
this.listBox2.Items.Add("进程名:"+IsProcedding.ProcessName.ToString()+"--启动时间:"+currentTime.ToString());
this.listBox1.Items.Add(IsProcedding.ProcessName.ToString());
string message = "程序"+IsProcedding.ProcessName+"第一次运行是否允许该程序运行?";
string caption = "注意!";
MessageBoxButtons buttons = MessageBoxButtons.YesNo;
DialogResult result;
result=MessageBox.Show(this, message, caption, buttons);
if(result == DialogResult.No)
{
IsProcedding.Kill();
listBox1.Items.Remove(IsProcedding.ProcessName);
}
这个就变成对程序第一次运行时!会提示该程序第一次运行.
要是允许该程序运行.则下次运行该程序时默认为允许运行状态!
课程设计终于完成了
谢谢楼主帮忙!