using System; using System.Linq; using System.Collections.Generic; using System.Windows.Forms; using System.Runtime.InteropServices; namespace DeiNiu.Wms.CE { static class Program { [DllImport("coredll.dll", EntryPoint = "FindWindow")] private extern static IntPtr FindWindow(string lpClassName, string lpWindowName); public static bool AppRunAlready(string appName) { IntPtr hDlg = IntPtr.Zero; hDlg = FindWindow(null, appName); if (hDlg != IntPtr.Zero) //如果程序已经启动 return true; else return false; } /// /// 应用程序的主入主函数。 /// [MTAThread] static void Main() { if (AppRunAlready("Login")) { MessageBox.Show("抱歉,W M S已启动,请关闭"); Application.Exit(); } else Application.Run(new login(false)); } } }