📄 form1.cs
字号:
int Extension = e.FullPath.LastIndexOf(".");
string ExtensionName = e.FullPath.Substring(Extension + 1);//获取扩展名
if (ExtensionName == "ini" || ExtensionName == "INI" || ExtensionName == "exe" || ExtensionName == "EXE" || ExtensionName == "inf" || ExtensionName == "INF")
{
listBoxWatch.Items.Add("创建的文件:" + e.FullPath.ToString());
listBoxWatch.Items.Add("创建时间:" + File.GetCreationTime(e.FullPath));
StreamWriter wr;
wr = File.AppendText("watch.txt");
wr.WriteLine("创建的文件:" + e.FullPath.ToString());
wr.WriteLine("创建时间:" + File.GetCreationTime(e.FullPath));
if (auto)
{
File.Delete(e.FullPath);
wr.WriteLine("删除被修改的文件:" + e.FullPath);
wr.WriteLine("删除时间:" + File.GetLastAccessTime(e.FullPath).ToString());
listBoxWatch.Items.Add("删除被修改的文件:" + e.FullPath);
listBoxWatch.Items.Add("删除时间:" + File.GetLastAccessTime(e.FullPath).ToString());
}
wr.Flush();
wr.Close();
}
}
catch
{
}
}
private void fileSystemWatcher1_Deleted(object sender, FileSystemEventArgs e)//文件系统的删除事件
{
try
{
//MessageBox.Show("delete!");
int Extension = e.FullPath.LastIndexOf(".");
string ExtensionName = e.FullPath.Substring(Extension + 1);
if (ExtensionName == "ini" || ExtensionName == "INI" || ExtensionName == "exe" || ExtensionName == "EXE" || ExtensionName == "inf" || ExtensionName == "INF")
{
listBoxWatch.Items.Add("被删除的文件:" + e.FullPath.ToString());
listBoxWatch.Items.Add("删除时间:" + File.GetLastAccessTime(e.FullPath));
StreamWriter wr;
wr = File.AppendText("watch.txt");
wr.WriteLine("被删除的文件:" + e.FullPath.ToString());
wr.WriteLine("删除时间:" + File.GetLastAccessTime(e.FullPath));
wr.Flush();
wr.Close();
}
}
catch
{
}
}
private void ziDong_Click(object sender, EventArgs e)//“自动”按钮
{
if (autostop)
{
auto = true;//启动自动删除功能
autostop = false;
ziDong.Text = "手动";
}
else
{
auto = false;
autostop = true;
ziDong.Text = "自动";
}
}
private void fileSystemWatcher1_Renamed(object sender, RenamedEventArgs e)//文件系统重命名事件
{
try
{
// MessageBox.Show("renamed!");
int Extension = e.FullPath.LastIndexOf(".");
string ExtensionName = e.FullPath.Substring(Extension + 1);
if (ExtensionName == "ini" || ExtensionName == "INI" || ExtensionName == "exe" || ExtensionName == "EXE" || ExtensionName == "inf" || ExtensionName == "INF")
{
listBoxWatch.Items.Add("被重命名的文件:" + e.FullPath.ToString());
listBoxWatch.Items.Add("重命名时间:" + File.GetLastAccessTime(e.FullPath));
StreamWriter wr;
wr = File.AppendText("watch.txt");
wr.WriteLine("删除被重命名的文件:" + e.FullPath.ToString());
wr.WriteLine("删除时间:" + File.GetLastAccessTime(e.FullPath));
if (auto)//自动删除功能
{
File.Delete(e.FullPath);
wr.WriteLine("删除被重命名的文件:" + e.FullPath);
wr.WriteLine("删除时间:" + File.GetLastAccessTime(e.FullPath).ToString());
listBoxWatch.Items.Add("删除被重命名的文件:" + e.FullPath);
listBoxWatch.Items.Add("删除时间:" + File.GetLastAccessTime(e.FullPath).ToString());
}
wr.Flush();
wr.Close();
}
}
catch
{
}
}
private void shanChu_Click(object sender, EventArgs e)//“删除”按钮
{
try
{
int g = listBoxWatch.SelectedItem.ToString().CompareTo(comboBox2.SelectedItem.ToString());//判断选中的路径含有硬盘符
listBoxProcess2.Items.Add(g.ToString());
if (g == 1)//含有
{
File.Delete(listBoxWatch.SelectedItem.ToString());
listBoxWatch.Items.Add("手动删除了文件:" + listBoxWatch.SelectedItem.ToString());
listBoxWatch.Items.Add("手动删除文件时间:" + listBoxWatch.SelectedItem.ToString());
StreamWriter wr;
wr = File.AppendText("watch.txt");
wr.WriteLine("手动删除了文件:" + listBoxWatch.SelectedItem.ToString());
wr.WriteLine("手动删除文件时间:" + listBoxWatch.SelectedItem.ToString());
wr.Flush();
wr.Close();
}
else//不含有
{
MessageBox.Show("非法路径!");
}
}
catch//Exception err)
{
MessageBox.Show("不能删除!");
}
}
private void jiLu_Click(object sender, EventArgs e)//“记录”按钮
{
try
{
Process.Start("watch.txt");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void qingChu_Click(object sender, EventArgs e)//“清除”按钮
{
StreamWriter wr = new StreamWriter("watch.txt", false);
wr.Write("");
wr.Flush();
wr.Close();
}
//private void liuLan_Click(object sender, EventArgs e)//
//{
// openFileDialog1.InitialDirectory = "c:\\";
// openFileDialog1.Filter = "*.*|*.*";
// openFileDialog1.RestoreDirectory = true;
// if (openFileDialog1.ShowDialog() == DialogResult.OK)
// {
// int n = openFileDialog1.FileName.LastIndexOf("\\");
// string directory = openFileDialog1.FileName.Substring(0, n + 1);
// //textBoxWatchADD.Text = directory;
// fileSystemWatcher1.Path = directory;
// }
//}
private void shuoMing_Click(object sender, EventArgs e)//“说明”按钮
{
try
{
Process.Start("readme.txt");
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void listBoxProcess1_DoubleClick(object sender, EventArgs e)//新添加进程的显示框的双击事件
{
try
{
Process[] prc=Process.GetProcessesByName(listBoxProcess1.SelectedItem.ToString());
//listBoxProcess2.Items.Add(listBoxProcess1.SelectedIndex.ToString());
prc[0].Kill();
//listBoxWatch.Items.Add(prc[0].ProcessName.ToString());
}
catch //(Exception err)
{
//MessageBox.Show(err.Message);
}
}
//private void checkBox3_CheckedChanged(object sender, EventArgs e)
//{
//}
private void qieDing_Click(object sender, EventArgs e)//“确定”按钮,确定文件系统监控的路径
{
try
{
fileSystemWatcher1.Path = comboBox2.SelectedItem.ToString();//设置文件系统监控路径
//fileSystemWatcher1.EnableRaisingEvents = false;
groupBox2.Text = "文件系统监控:" + comboBox2.SelectedItem.ToString();
}
catch (Exception err)
{
MessageBox.Show(err.Message);
}
}
private void button3_Click(object sender, EventArgs e)//“通辑”按钮
{
if (tongJiIndex < 5)//通辑的进程个数只能是5个
{
//if (listBoxProcess1.SelectedIndex != -1)
//{
// tongJi[tongJiIndex++] = listBoxProcess1.SelectedItem.ToString();
// comboBox1.Items.Add(listBoxProcess1.SelectedItem.ToString());
// comboBox1.SelectedIndex = 0;
//}
//else
//{
// MessageBox.Show("请选择一个犯罪的进程!");
//}
if (yanJingChenProcess.SelectedIndex != -1)//在“原进程”里选中一个进程,-1是没选中
{
try
{
tongJi[tongJiIndex++] = processStr[yanJingChenProcess.SelectedIndex];//把该进程保存起来
comboBox1.Items.Add(processStr[yanJingChenProcess.SelectedIndex]);//把该进程显示出来
comboBox1.SelectedIndex = 0;
}
catch
{
}
}
else
{
MessageBox.Show("请选择一个犯罪的进程!");
}
//listBoxProcess2.Items.Add(tongJiIndex.ToString());
}
else
{
MessageBox.Show("请解除一些最近没有犯罪的进程!");
}
}
private void timer2_Tick(object sender, EventArgs e)//实时监控被通辑的进程
{
for (int i = 0; i < tongJiIndex; i++)
{
if (tongJi[i] != "")//有被通辑的进程
{
try
{
Process[] pr = Process.GetProcessesByName(tongJi[i]);//获取该进程
pr[0].Kill();//结束该进程
}
catch //(Exception err)
{
// MessageBox.Show(err.Message);
}
}
}
}
private void jieChu_Click(object sender, EventArgs e)//“解除”按钮
{
if (comboBox1.Items.Count>0)//显示框的有通辑进程
{
for (int i = (int)comboBox1.Items.IndexOf(comboBox1.SelectedItem); i < tongJiIndex; i++)
{
tongJi[i] = tongJi[i + 1];//解除之后,tongJi字符数组要进行更新,即解除通辑
}
}
comboBox1.Items.Remove(comboBox1.SelectedItem);
if (comboBox1.Items.Count >=1)
{
comboBox1.SelectedIndex = 0;
}
if (comboBox1.Items.Count == 0)
kong++;
if (kong == 2)
{
kong = 0;
MessageBox.Show("已经全部解除!!");
}
//listBoxProcess2.Items.Add(comboBox1.Items.Count.ToString());
}
private void button1_Click(object sender, EventArgs e)//“进程的相关模块”按钮
{
ProcessModuleCollection modules;
Process[] proc;
proc = Process.GetProcessesByName(processStr[yanJingChenProcess.SelectedIndex]);
try
{
modules = proc[0].Modules;
listBoxProcess2.Items.Clear();
foreach (ProcessModule mod in modules)
{
listBoxProcess2.Items.Add(mod.FileName);
}
}
catch
{
MessageBox.Show("该进程已经死了!");
}
}
private void shuaXing_Click(object sender, EventArgs e)//“刷新“按钮
{
string[] u = Directory.GetLogicalDrives();
comboBox2.Items.Clear();
foreach (string y in u)
{
comboBox2.Items.Add(y);
}
comboBox2.SelectedIndex = 0;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -