/// <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); }
/// <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)]); }