Advertisement
Guest User

Untitled

a guest
May 28th, 2015
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Diagnostics;
  5. using System.Text.RegularExpressions;
  6. using System.IO;
  7. using System.Timers;
  8.  
  9. namespace ProcessControl
  10. {
  11.     class Program
  12.     {
  13.         static void Main(string[] args)
  14.         {
  15.  
  16.             if (File.Exists("rules.txt"))
  17.             {
  18.                 string[] ruleList;
  19.                 string rules = File.ReadAllText("rules.txt");
  20.                 ruleList = rules.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
  21.                 while (true)
  22.                 {
  23.                     if (File.Exists("lockfile"))
  24.                     {
  25.                         Process[] procList = Process.GetProcesses();
  26.                         foreach (Process proc in procList)
  27.                         {
  28.                             string moduleName = "";
  29.                             try
  30.                             {
  31.                                 moduleName = proc.Modules[0].FileName;
  32.                             }catch{
  33.  
  34.                             }
  35.  
  36.                             if (!Regex.IsMatch(moduleName, "Windows", RegexOptions.IgnoreCase))
  37.                             {
  38.                                 bool toKill = true;
  39.                                 foreach (string rule in ruleList)
  40.                                 {
  41.                                     if (proc.ProcessName == rule.Trim())
  42.                                     {
  43.                                         toKill = false;
  44.                                     }
  45.                                 }
  46.  
  47.                                 if (toKill == true)
  48.                                 {
  49.                                     try
  50.                                     {
  51.                                         proc.Kill();
  52.                                     }
  53.                                     catch (Exception ex)
  54.                                     {
  55.                                         File.AppendAllText("error.log",ex.Message + "\r\n");
  56.                                     }
  57.  
  58.                                 }
  59.                             }
  60.                         }
  61.                     }
  62.                     ruleList = rules.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntries);
  63.                 }
  64.  
  65.             }
  66.         }
  67.  
  68.         static void smartTick_Elapsed(object sender, ElapsedEventArgs e)
  69.         {
  70.            
  71.            
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement