c# 如何判断一个程序有没有打开
2个回答
展开全部
通过查找窗口句柄名称或者进程
窗口句柄:
IntPtr hwWnd = new IntPtr(0);
hwWnd = WindowFind("窗口名称");
/// <summary>
/// 获取窗体句柄
/// </summary>
/// <param name="WindowName">窗体名</param>
/// <returns>窗体句柄</returns>
public static IntPtr WindowFind(string WindowName)
{
IntPtr ParenthWnd = new IntPtr(0);
ParenthWnd = FindWindow(null, WindowName);
return ParenthWnd;
}
进程:
Process[] pro = Process.GetProcesses();
for (int i = 0; i < pro.Length; i++)
{
if (pro[i].ProcessName == "进程名字")
{
MessageBox.Show("运行");
}
}
窗口句柄:
IntPtr hwWnd = new IntPtr(0);
hwWnd = WindowFind("窗口名称");
/// <summary>
/// 获取窗体句柄
/// </summary>
/// <param name="WindowName">窗体名</param>
/// <returns>窗体句柄</returns>
public static IntPtr WindowFind(string WindowName)
{
IntPtr ParenthWnd = new IntPtr(0);
ParenthWnd = FindWindow(null, WindowName);
return ParenthWnd;
}
进程:
Process[] pro = Process.GetProcesses();
for (int i = 0; i < pro.Length; i++)
{
if (pro[i].ProcessName == "进程名字")
{
MessageBox.Show("运行");
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询