using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace Sci
{
/// <summary>
/// 进程判断处理工具(判断进程运行状态,结束进程)
/// </summary>
class ProcessTool
{
public static void example()
{
KillProcess("qq.exe");
}
/// <summary>
/// 结束指定名称的进程
/// </summary>
public static void KillProcess(String exeFile)
{
String name = Path.GetFileNameWithoutExtension(exeFile);
KillProcessByName(name);
}
/// <summary>
/// 结束指定名称的进程
/// </summary>
public static void KillProcessByName(String processName)
{
//Process current = Process.GetCurrentProcess(); // 当前进程
//current.ProcessName // 当前进程名
Process[] processes = Process.GetProcessesByName(processName); // 获取指定名称的进程
foreach (Process process in processes)
{
try
{
process.Kill();
}
catch (Exception) { }
}
}
/// <summary>
/// 判断指定名称的进程是否正在运行,如qq.exe
/// </summary>
public static bool ProcessIsRunning(String processName)
{
if (File.Exists(processName)) processName = Path.GetFileNameWithoutExtension(processName);
Process[] processes = Process.GetProcessesByName(processName); // 获取指定名称的进程
return (processes != null && processes.Length > 0);
}
}
}
Process进程判断处理(判断进程运行状态,结束进程)
最新推荐文章于 2024-07-17 17:06:56 发布