Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Diagnostics;
- using System.Text.RegularExpressions;
- using System.IO;
- using System.Timers;
- namespace ProcessControl
- {
- class Program
- {
- static void Main(string[] args)
- {
- if (File.Exists("rules.txt"))
- {
- string[] ruleList;
- string rules = File.ReadAllText("rules.txt");
- ruleList = rules.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
- while (true)
- {
- if (File.Exists("lockfile"))
- {
- Process[] procList = Process.GetProcesses();
- foreach (Process proc in procList)
- {
- string moduleName = "";
- try
- {
- moduleName = proc.Modules[0].FileName;
- }catch{
- }
- if (!Regex.IsMatch(moduleName, "Windows", RegexOptions.IgnoreCase))
- {
- bool toKill = true;
- foreach (string rule in ruleList)
- {
- if (proc.ProcessName == rule.Trim())
- {
- toKill = false;
- }
- }
- if (toKill == true)
- {
- try
- {
- proc.Kill();
- }
- catch (Exception ex)
- {
- File.AppendAllText("error.log",ex.Message + "\r\n");
- }
- }
- }
- }
- }
- ruleList = rules.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
- }
- }
- }
- static void smartTick_Elapsed(object sender, ElapsedEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement