当前电脑判断某个程序是否正在运行,可直接获取该程序运行的进程,如果获取不到,则表示不在运行.
/// <summary>
/// 获取当前正在运行的应用程序
/// </summary>
/// <param name="name">应用程序名称</param>
/// <returns></returns>
public Process ProcessGet(string name)
{
var processes = Process.GetProcessesByName(name);
if (processes == null || processes.Length <= 0) return null;
foreach (var thisproc in processes)
{
var strBuilder = new StringBuilder(256);
Win32.GetWindowText(thisproc.MainWindowHandle, strBuilder, 256);
var txt = strBuilder.ToString();
if (string.IsNullOrEmpty(txt)) return thisproc;
if ("BOSSLOGIN:" + name == txt) return thisproc;
if (txt.IndexOf("BOSSLOGIN:") == 0) continue;
return thisproc;
}
return null;
}
将应用程序的窗体至于最前方显示
public Point ProcessShow(Process pross)
{
Win32.RECT rect;
Win32.GetWindowRect(pross.MainWindowHandle, out rect);
Point _point = new Point(rect.Left, rect.Top);
Win32.ShowWindow(pross.MainWindowHandle, Win32.WindowAction.Show);
Win32.SetForegroundWindow(pross.MainWindowHandle);
return _point;
}