Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a program is using .NET?

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

like image 473
cpx Avatar asked Jan 17 '10 05:01

cpx


People also ask

How do I identify .NET applications?

If you suspect that an application might be a . NET application simply start it and check the process column again for that app. In this case, the first instance I find is Microsoft AD web services. 7) Right-click the service that is highlighted in yellow and select Properties.

How do I know if an application is .NET core?

NET Core is installed on Windows is: Press Windows + R. Type cmd. On the command prompt, type dotnet --version.

How do I tell what version of .NET a file is using?

Use Registry Editor (older framework versions) From the Start menu, choose Run, enter regedit, and then select OK. You must have administrative credentials to run regedit. Open the subkey that matches the version you want to check. Use the table in the Detect .NET Framework 1.0 through 4.0 section.

How can I tell if an application is running or not in C#?

GetProcessById() function in C#. In the above code, we created a function isRunning() that checks if a process is running or not. The isRunning() function takes the process id as an argument and returns true if the process is running and returns false if it is not running.


4 Answers

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();
}
like image 127
Igal Tabachnik Avatar answered Oct 06 '22 15:10

Igal Tabachnik


Use the CLR COM interfaces ICorPublish and ICorPublishProcess. The easiest way to do this from C# is to borrow some code from SharpDevelop's debugger, and do the following:

ICorPublish publish = new ICorPublish();
ICorPublishProcess process;

process = publish.GetProcess(PidToCheck);

if (process == null || !process.IsManaged)
{
    // Not managed.
}
else
{
    // Managed.
}
like image 20
wj32 Avatar answered Oct 06 '22 15:10

wj32


Use System.Reflection.Assembly.LoadFrom function to load the .exe file. This function will throw exception if you try to load binary file that is not .NET assembly.

like image 8
lubos hasko Avatar answered Oct 06 '22 14:10

lubos hasko


I know this is about a million years too late, but in case it helps - my favourite method to figure out if an exe is using .net is to run MSIL disassembler against it which comes with .net SDK. If a .net exe you indeed have, you'll get a nice graphical breakdown of its contents; if a plain old win32 exe it be, you'll get a message telling you so.

like image 7
Dan Avatar answered Oct 06 '22 14:10

Dan