Пример #1
0
 public void BlockApplications(object sender, ProcessEventArgs e)
 {
     foreach (string item in blockedApplications) //For every item in the list of blocked applications...
     {
         if (blockType == BlockType.Blacklist)
         {
             foreach (Process p in e.RelatedProcesses)
             {
                 if (p.MainWindowTitle.Contains(item)) //If the process related to the event matches a blocked application...
                 {
                     p.Kill();                         //Kill the process associated with the event.
                     blockedApplication = item;
                     ApplicationBlocked?.Invoke(this, new EventArgs());
                 }
             }
         }
         else
         {
             foreach (Process p in e.RelatedProcesses)
             {
                 if (p.MainWindowTitle.Contains(item)) //If the process related to the event does not match a whitelisted application...
                 {
                     p.Kill();                         //Kill the process associated with the event.
                     blockedApplication = item;
                     ApplicationBlocked?.Invoke(this, new EventArgs());
                 }
             }
         }
     }
 }
Пример #2
0
 public ApplicationBlocker(List <string> blockedApplications)
 {
     this.blockedApplications           = blockedApplications;
     applicationWatcher.ProcessStarted += new ProcessWatcher.ProcessEventHandler(BlockApplications);
     applicationWatcher.Start();
     foreach (Process p in Process.GetProcesses())
     {
         foreach (string item in blockedApplications)
         {
             if (p.MainWindowTitle.Contains(item))
             {
                 p.Kill();
                 blockedApplication = item;
                 ApplicationBlocked?.Invoke(this, new EventArgs());
             }
         }
     }
 }
 /// <summary>
 ///     Handles IOEvents. Invokes ApplicationBlocked
 /// </summary>
 /// <param name="type"></param>
 /// <param name="data"></param>
 private void OnIOEvent(short type, byte data)
 {
     ApplicationBlocked?.Invoke(this, new IoEventArgs(type, data));
 }