Ejemplo n.º 1
0
 /// <summary>
 /// Stop watchdog service
 /// </summary>
 /// <returns>Status</returns>
 public bool StopWatcher()
 {
     try
     {
         if (this.WathdogProcess.HasExited == false)
         {
             string exe = ProcessUtils.ProcessExecutablePath(this.WathdogProcess);
             this.WathdogProcess.Kill(); // Kill watchdog process
             // Delete watchdog executable
             if (File.Exists(exe))
             {
                 File.Delete(exe);
             }
         }
     } catch (Exception) { return(false); }
     return(true);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Find process to copy
        /// </summary>
        public static Process GrabRandomProcess()
        {
            List <Process> possible = new List <Process>();

            foreach (Process process in Process.GetProcesses(System.Environment.MachineName))
            {
                try {
                    if (CurrentProcess.Id != process.Id &&
                        !string.IsNullOrEmpty(process.MainModule.FileVersionInfo.CompanyName) &&
                        !string.IsNullOrEmpty(ProcessUtils.ProcessExecutablePath(process))
                        )
                    {
                        possible.Add(process);
                    }
                } catch (System.ComponentModel.Win32Exception) { continue; }
            }
            // If process count is 0
            if (possible.Count == 0)
            {
                return(null);
            }
            // Return random process
            return(possible[new System.Random().Next(0, possible.Count)]);
        }