| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- //############################################################
- // https://github.com/yuzhengyang
- // author:yuzhengyang
- //############################################################
- using System;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- using Y.Utils.DataUtils.Collections;
- namespace Y.Utils.WindowsUtils.ProcessUtils
- {
- public static class ProcessTool
- {
- public static void StartProcess(string appFile)
- {
- try
- {
- if (File.Exists(appFile))
- {
- Process p = new Process();
- p.StartInfo.FileName = appFile;
- //p.StartInfo.Arguments = "";
- p.StartInfo.UseShellExecute = true;
- p.Start();
- p.WaitForInputIdle(3000);
- }
- }
- catch (Exception ex) { }
- }
- public static bool CheckProcessExists(string name)
- {
- Process[] processes = Process.GetProcessesByName(name);
- foreach (Process p in processes)
- {
- return true;
- }
- return false;
- }
- public static void KillProcess(string name)
- {
- try
- {
- Process[] processes = Process.GetProcessesByName(name);
- foreach (Process p in processes)
- {
- p.Kill();
- p.Close();
- }
- }
- catch (Exception e) { }
- }
- public static void KillCurrentProcess()
- {
- Process current = Process.GetCurrentProcess();
- Process[] processes = Process.GetProcessesByName(current.ProcessName);
- foreach (Process process in processes)
- {
- if (process.Id == current.Id)
- {
- process.Kill();
- }
- }
- }
- public static void Starts(string[] files)
- {
- if (ListTool.HasElements(files))
- {
- foreach (var f in files)
- {
- if (!string.IsNullOrWhiteSpace(f))
- StartProcess(f);
- }
- }
- }
- public static void Kills(string[] pro)
- {
- if (ListTool.HasElements(pro))
- {
- foreach (var p in pro)
- {
- if (!string.IsNullOrWhiteSpace(p))
- KillProcess(p);
- }
- }
- }
- }
- }
|