Example #1
0
        public static IEnumerable <Process> GetProcesses(string exeFile)
        {
            string exeFileDir = PathRoutines.GetFileDir(exeFile).ToLower();

            return(Process.GetProcessesByName(PathRoutines.GetFileNameWithoutExtention(exeFile)).Where(p =>
            {
                ProcessModule pm;
                try
                {
                    pm = p.MainModule;
                }
                catch//sometimes it throws exception (if the process exited?)
                {
                    pm = null;
                }
                return pm == null ? false : pm.FileName.StartsWith(exeFileDir, StringComparison.InvariantCultureIgnoreCase);
            }
                                                                                                       ));
        }