Esempio n. 1
0
        protected static string GetProcessList()
        {
            string   fileFullName = Assembly.GetExecutingAssembly().Location;
            FileInfo fInfo        = new FileInfo(fileFullName);
            string   currPath     = fInfo.Directory.ToString();
            string   cfgPath      = string.Format("{0}\\{1}", currPath, IOA_CFG_PATH);

            if (!File.Exists(cfgPath))
            {
                FileLog.ERR(string.Format("IOA Cfg file not exists. ({0})", cfgPath), true);
                return(null);
            }

            StringBuilder sb = new StringBuilder();

            WIN32.GetPrivateProfileString("Watch", "list", null, sb, 255, cfgPath);
            return(sb.ToString());
        }
Esempio n. 2
0
        /// <summary>
        /// OnStart: Put startup code here
        ///  - Start threads, get inital data, etc.
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            //string procList = GetProcessList();
            //FileLog.MSG(string.Format("LIST={0}", procList), true);

            string   fileFullName = Assembly.GetExecutingAssembly().Location;
            FileInfo fInfo        = new FileInfo(fileFullName);
            string   currPath     = fInfo.Directory.ToString();
            ////string currPath = AppDomain.CurrentDomain.BaseDirectory;

            string cfgPath = string.Format("{0}\\{1}", currPath, IOA_CFG_PATH);

            if (!File.Exists(cfgPath))
            {
                FileLog.ERR(string.Format("IOA Cfg file not exists. ({0})", cfgPath), true);
                return;
            }

            string section = "IFIOA";
            string filePath;
            string fileName;
            string startArg;

            StringBuilder sb = new StringBuilder();

            WIN32.GetPrivateProfileString(section, "Path", null, sb, 255, cfgPath);
            filePath = sb.ToString();

            WIN32.GetPrivateProfileString(section, "ExeName", null, sb, 255, cfgPath);
            fileName = sb.ToString();

            WIN32.GetPrivateProfileString(section, "StartArg", null, sb, 255, cfgPath);
            startArg = sb.ToString();

            StartProc(filePath, fileName, startArg, false);

            //base.OnStart(args);
        }
Esempio n. 3
0
        protected static void DisplayProcessInfo(string[] args)
        {
            string procList = GetProcessList();

            FileLog.MSG(string.Format("LIST={0}", procList), true);

            if (args.Length <= 1)
            {
                FileLog.WRN("Invalid Process Name.", true);
                return;
            }

            if (args[1].ToLower().Trim() == "list")
            {
                return;
            }

            string procName = args[1].ToUpper().Trim();
            string section  = "";

            string[] procs = procList.Split(',');
            foreach (string str in procs)
            {
                if (str == procName)
                {
                    section = str;
                    break;
                }
            }

            if (string.IsNullOrEmpty(section))
            {
                return;
            }

            string cfgPath = string.Format("{0}\\{1}", Directory.GetCurrentDirectory(), IOA_CFG_PATH);

            if (!File.Exists(cfgPath))
            {
                FileLog.ERR(string.Format("IOA Cfg file not exists. ({0})", cfgPath), true);
                return;
            }

            StringBuilder sb = new StringBuilder();

            WIN32.GetPrivateProfileString(section, "0", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("RoloID:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "OnOff", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("OnOff:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "Method", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("Method:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "ExeName", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("ExeName:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "Path", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("Path:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "Pattern", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("Pattern:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "Run", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("Run:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "RunWaitTime", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("RunWaitTime:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "StartCmd", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("StartCmd:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "StartArg", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("StartArg:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "StopMethod", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("StopMethod:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "StopCmd", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("StopCmd:{0}", sb.ToString()), true);

            WIN32.GetPrivateProfileString(section, "StopArg", null, sb, 255, cfgPath);
            FileLog.MSG(string.Format("StopArg:{0}", sb.ToString()), true);
        }
Esempio n. 4
0
        protected static void KillProc(string[] args)
        {
            //Console.Clear();
            List <ProcItem> tmpProc = new List <ProcItem>();

            string procList = GetProcessList();

            FileLog.MSG(string.Format("LIST={0}", procList), true);
            string[] sections = procList.Split(',');
            if (sections.Length <= 0)
            {
                return;
            }

            if (args.Length <= 1)
            {
                FileLog.WRN("Invalid Process Name.", true);
                return;
            }

            string[] procLst = args[1].ToString().Split(',');
            if (procLst.Length <= 0)
            {
                return;
            }

            string procName;
            string section;

            // 전체 프로세스 목록 수집
            CollectAllProcInfo();

            if (args[1].ToLower().Trim() == "all")
            {
                FileLog.MSG("All process kill !!", true);
                procLst = procList.Split(',');
            }

            foreach (string arg in procLst)
            {
                System.Threading.Thread.Sleep(300);
                tmpProc.Clear();
                procName = "";
                procName = arg.ToUpper().Trim();

                // get section
                section = "";
                foreach (string str in sections)
                {
                    if (str.ToUpper().Trim() == procName)
                    {
                        section = str;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(section))
                {
                    FileLog.WRN(string.Format("Not Found Data Section.({0})", procName), true);
                    continue;
                }

                // get filepath
                string currPath = AppDomain.CurrentDomain.BaseDirectory;
                string cfgPath  = string.Format("{0}\\{1}", currPath, IOA_CFG_PATH);
                //string cfgPath = string.Format("{0}\\{1}", Directory.GetCurrentDirectory(), IOA_CFG_PATH);
                //FileLog.MSG(string.Format("curr_path:{0}, ioa_cfg_path:{1}", currPath, cfgPath), true);
                if (!File.Exists(cfgPath))
                {
                    FileLog.ERR(string.Format("IOA Cfg file not exists. ({0})", cfgPath), true);
                    return;
                }

                string filePath;
                string fileName;
                string startArg;

                StringBuilder sb = new StringBuilder();
                WIN32.GetPrivateProfileString(section, "Path", null, sb, 100, cfgPath);
                filePath = sb.ToString().Trim();

                sb.Clear();
                WIN32.GetPrivateProfileString(section, "ExeName", null, sb, 100, cfgPath);
                fileName = sb.ToString().Trim();

                sb.Clear();
                WIN32.GetPrivateProfileString(section, "StartArg", null, sb, 100, cfgPath);
                startArg = sb.ToString().Trim();


                FileLog.MSG(string.Format("Section:[{0}], FilePath:{1}, FileNae:{2}, StartArg:{3}", section, filePath, fileName, startArg), true);

                try
                {
                    foreach (KeyValuePair <int, ProcItem> pair in m_procInfoCollection)
                    {
                        if (pair.Value.ProcName.ToString() == fileName.Replace(".exe", "").Trim())
                        {
                            tmpProc.Add(pair.Value);
                        }
                    }

                    if (tmpProc.Count <= 0)
                    {
                        FileLog.WRN(string.Format("Not Found Data : file_path:{0}, fileName:{1}, startArg:{2}", filePath, fileName, startArg), true);
                        continue;
                    }

                    foreach (ProcItem item in tmpProc)
                    {
                        if (item.commandLine.Contains(startArg))
                        {
                            Process.GetProcessById(item.pid).Kill();
                            FileLog.MSG(string.Format("Process Kill:{0}, {1}", item.ProcName, item.commandLine), true);
                        }
                    }
                }
                catch (Exception ex)
                {
                    FileLog.MSG(string.Format("{0}", ex.Message));
                }
            }
        }
Esempio n. 5
0
        protected static void ExecProc(string[] args)
        {
            string procList = GetProcessList();

            FileLog.MSG(string.Format("LIST={0}", procList), true);

            if (args.Length <= 1)
            {
                FileLog.WRN("Invalid Process Name.", true);
                return;
            }

            string[] procLst = args[1].ToString().Split(',');
            if (procList.Length <= 0)
            {
                return;
            }

            foreach (string arg in procLst)
            {
                System.Threading.Thread.Sleep(500);
                FileLog.MSG("--------------------------------------------------------------------------------------------", true);
                string procName = arg.ToUpper().Trim();

                string   section = "";
                string[] procs   = procList.Split(',');
                foreach (string str in procs)
                {
                    if (str == procName)
                    {
                        section = str;
                        break;
                    }
                }

                if (string.IsNullOrEmpty(section))
                {
                    FileLog.WRN(string.Format("Not Found Data.({0})", procName), true);
                    return;
                }

                //string fileFullName = Assembly.GetExecutingAssembly().Location;
                //FileInfo fInfo = new FileInfo(fileFullName);
                //string currPath = fInfo.Directory.ToString();
                string currPath = AppDomain.CurrentDomain.BaseDirectory;
                string cfgPath  = string.Format("{0}\\{1}", currPath, IOA_CFG_PATH);
                //string cfgPath = string.Format("{0}\\{1}", Directory.GetCurrentDirectory(), IOA_CFG_PATH);
                if (!File.Exists(cfgPath))
                {
                    FileLog.ERR(string.Format("IOA Cfg file not exists. ({0})", cfgPath), true);
                    return;
                }

                string filePath;
                string fileName;
                string startArg;

                StringBuilder sb = new StringBuilder();
                WIN32.GetPrivateProfileString(section, "Path", null, sb, 255, cfgPath);
                filePath = sb.ToString();

                WIN32.GetPrivateProfileString(section, "ExeName", null, sb, 255, cfgPath);
                fileName = sb.ToString();

                WIN32.GetPrivateProfileString(section, "StartArg", null, sb, 255, cfgPath);
                startArg = sb.ToString();

                StartProc(filePath, fileName, startArg, false);
            }
        }