识别正在使用CLR的进程

时间:2018-08-24 22:33:23

标签: c# .net

下面的代码未列出w3wp进程,winforms应用程序进程! 如何为w3wp进程标识应用程序池。这种方法正确吗?

代码

public static List<String> GetCLRManagedProcesses()
    {
        var managedProcesses = new List<Process>();
        foreach (var process in Process.GetProcesses())
        {
            try
            {
                if (process != null && !process.HasExited)
                {
                    for (int i = 0; (i < process.Modules.Count); i++)
                    {
                        try
                        {
                            var moduleName = process.Modules[i].ModuleName.ToLowerInvariant();
                            if (FrameworkLibraries().Contains(moduleName))
                            {
                                managedProcesses.Add(process);
                            }
                            else
                            {
                                // winforms, w3wp, all are entering here
                            }
                        }
                        catch (Exception e){ }
                    }
                }
            }
            catch (Exception ex) 
            {
            }
        }

        return managedProcesses
            .Select(x => x.ProcessName)
            .ToList();
    }

    private static IEnumerable<String> FrameworkLibraries()
    {
        return new[] { "mscoree.dll", "mscoreei.dll", "mscorwks.dll" };
    }

任何帮助表示赞赏

0 个答案:

没有答案