| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- //############################################################
- // https://github.com/yuzhengyang
- // author:yuzhengyang
- //############################################################
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Windows.Forms;
- 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();
- }
- }
- }
- }
- }
|