How to check if a program is using .NET?

.net, executable, process

Solution

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();
}

Problem

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

Original source

Related problems