using System.Diagnostics; using System.Threading; namespace ToolKit { public class StarterTool { public static bool IsExistMutex(string mutexName, out Mutex mutex) { bool flag; mutex = new Mutex(true, mutexName, out flag); return !flag; } public static bool IsSingle() { return (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length <= 1); } public static void PowerWait(string[] args) { if ((((args != null) && (args.Length > 1)) && args[0].ToUpper().Equals("-S")) && (args[1] != null)) { int result = 0; if (int.TryParse(args[1], out result) && (result > 0)) { Thread.Sleep((int) (result * 0x3e8)); } } } //private void Form1_Load(object sender, EventArgs e) //{ // string appPath = @"C:\Program Files\KEPServerEx\servermain.exe E:\MacBookTest_F2\Kep_F2.opf"; // int sleepTime = 200; // bool isVisible = false; // KillApp(appPath); // ShowWindow(appPath, sleepTime, isVisible); //} public static void ShowWindow(string appPathNargs, int sleepTime, bool isVisible) { int exeStart = appPathNargs.IndexOf(".exe", 0); string appPath = appPathNargs.Substring(0, exeStart + 4); string args = appPathNargs.Substring(exeStart + 5); System.Diagnostics.Process p = System.Diagnostics.Process.Start(appPath, args); System.Threading.Thread.Sleep(sleepTime); string name = p.MainWindowTitle; System.IntPtr ptr = HideIcon.Win32API.FindWindow(null, name); HideIcon.Win32API.ShowWindow(ptr, System.Convert.ToInt32(isVisible)); } public static void KillApp(string appPath) { int exeStart = appPath.IndexOf(".exe", 0); string[] appNames = appPath.Substring(0, exeStart).Split('\\'); string appName = appNames[appNames.Length - 1]; System.Diagnostics.Process[] pList = System.Diagnostics.Process.GetProcesses(); foreach (System.Diagnostics.Process item in pList) { if (item.ProcessName.ToUpper().Equals(appName.ToUpper())) { item.Kill(); } } } } }