Esempio n. 1
0
        public void Run()
        {
            IList <Process> runningProcesses = _processManager.GetRunningProcesses(_options.ProcessNames);

            _log.InfoFormat("Number of processes found matching names {0} = {1}",
                            string.Join(", ", _options.ProcessNames), runningProcesses.Count);
            foreach (Process process in runningProcesses)
            {
                SetPriorities(process);
            }

            if (_options.Monitor)
            {
                _log.Info("Monitoring...");
                string query = "SELECT * FROM Win32_ProcessStartTrace WHERE "
                               +
                               string.Join(" OR ",
                                           _options.ProcessNames.Select(n => string.Format("ProcessName = \"{0}\"", n)));
                _log.DebugFormat("WQL query is [{0}]", query);
                var watcher = new ManagementEventWatcher(new WqlEventQuery(query));
                watcher.EventArrived += ProcessStartEvent;
                watcher.Start();
                Thread.Sleep(Timeout.Infinite);
            }
        }
Esempio n. 2
0
        public void Start(bool simulate = false)
        {
            var processes = processManager.GetRunningProcesses()
                            .ToList();

            processes.ForEach(proc =>
            {
                if (filter.IsEligibleForTermination(proc))
                {
                    Console.WriteLine($"Kill {proc.ProcessName}");

                    if (!simulate)
                    {
                        processManager.KillProcess(proc);
                    }
                }
            });
        }