c#,timer,winform,notifyicon,contextMenuStrip,定时查杀指定的进程,时间间隔可以设置,
2008-07-17 17:59 Virus-BeautyCode 阅读(1573) 评论(0) 编辑 收藏 举报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 WindowsApp
{
public partial class Form1 : Form
{
private string proName = string.Empty;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
proName = txtProcess.Text.Trim();
timer1.Interval =Convert.ToInt32( this.numericUpDown1.Value) * 1000;
if (timer1.Enabled == false)
timer1.Enabled = true;
this.Hide();
notifyIcon1.Visible = true;
}
private void Form1_Load(object sender, EventArgs e)
{
lblSecond.Text = Convert.ToString(this.numericUpDown1.Value);
lblSecond.Refresh();
if (timer1.Enabled == false)
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(proName))
{
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == proName)
{
p.Kill();
return;
}
}
}
}
private void MenuItemOpen_Click(object sender, EventArgs e)
{
if(timer1.Enabled==false)
timer1.Enabled = true;
}
private void MenuItemClose_Click(object sender, EventArgs e)
{
if(timer1.Enabled)
timer1.Enabled = false;
}
private void MenuItemExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
lblSecond.Text = Convert.ToString(this.numericUpDown1.Value);
lblSecond.Refresh();
}
private void MenuItemSetting_Click(object sender, EventArgs e)
{
this.Show();
//foreach (Form form in Application.OpenForms)
//{
// if (form.Name == "Form1")
// {
// form.Activate();
// form.WindowState = FormWindowState.Normal;
// form.StartPosition = FormStartPosition.CenterScreen;
// return;
// }
//}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsApp
{
public partial class Form1 : Form
{
private string proName = string.Empty;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
proName = txtProcess.Text.Trim();
timer1.Interval =Convert.ToInt32( this.numericUpDown1.Value) * 1000;
if (timer1.Enabled == false)
timer1.Enabled = true;
this.Hide();
notifyIcon1.Visible = true;
}
private void Form1_Load(object sender, EventArgs e)
{
lblSecond.Text = Convert.ToString(this.numericUpDown1.Value);
lblSecond.Refresh();
if (timer1.Enabled == false)
timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(proName))
{
foreach (Process p in Process.GetProcesses())
{
if (p.ProcessName == proName)
{
p.Kill();
return;
}
}
}
}
private void MenuItemOpen_Click(object sender, EventArgs e)
{
if(timer1.Enabled==false)
timer1.Enabled = true;
}
private void MenuItemClose_Click(object sender, EventArgs e)
{
if(timer1.Enabled)
timer1.Enabled = false;
}
private void MenuItemExit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void numericUpDown1_ValueChanged(object sender, EventArgs e)
{
lblSecond.Text = Convert.ToString(this.numericUpDown1.Value);
lblSecond.Refresh();
}
private void MenuItemSetting_Click(object sender, EventArgs e)
{
this.Show();
//foreach (Form form in Application.OpenForms)
//{
// if (form.Name == "Form1")
// {
// form.Activate();
// form.WindowState = FormWindowState.Normal;
// form.StartPosition = FormStartPosition.CenterScreen;
// return;
// }
//}
}
}
}