alvin.chen
2019-11-29 edf127edc771f715c49f86e91e768633f0a0ed93
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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();
                }
            }
        }
    }
}