How to check if a program is using .NET?

cpx picture cpx · Jan 17, 2010 · Viewed 25.5k times · Source

Can we check if a running application or a program uses .Net framework to execute itself?

Answer

Igal Tabachnik picture Igal Tabachnik · Jan 17, 2010

There's a trick I once learned from Scott Hanselman's list of interview questions. You can easily list all programs running .NET in command prompt by using:

tasklist /m "mscor*"

It will list all processes that have mscor* amongst their loaded modules.

We can apply the same method in code:

public static bool IsDotNetProcess(this Process process)
{
  var modules = process.Modules.Cast<ProcessModule>().Where(
      m => m.ModuleName.StartsWith("mscor", StringComparison.InvariantCultureIgnoreCase));

  return modules.Any();
}