Dlongnecker
Dlongnecker

Reputation: 3047

How to see if a .NET program is running

Is it possible to determine if a Microsoft .NET program is running on a windows computer?

Upvotes: 0

Views: 257

Answers (3)

George Johnston
George Johnston

Reputation: 32258

If you are attempting to identify processes/applications that are explicit to .NET, you should look for a dependency/module within the process that is specific to the .NET framework.

Below I am using mscorlib, as it's the first that comes to mind, as my hint to identify that the process is dependent on the .NET framework. e.g.

        var processes = Process.GetProcesses();
        foreach (var process in processes)
        {
            try
            {
                foreach (var module in process.Modules)
                {
                    if (module.ToString().Contains("mscorlib"))
                    {
                        Console.WriteLine(process);
                        break;
                    }
                }
            }
            catch { // Access violations }
        }

It's not bullet proof, as some processes cannot have their modules enumerated due to access restrictions, but if you run it, you'll see that it will pull back .NET dependent processes. Perhaps it will give you a good starting point to get you thinking in the right direction.

Upvotes: 2

Cheeso
Cheeso

Reputation: 192467

Check out CorPublishLibrary - a library that lets you interrogate all managed-code processes running on a machine.

alt text

Upvotes: 1

Tim Lloyd
Tim Lloyd

Reputation: 38444

The following will return true if there is one or more processes running that have the supplied name.

    public bool IsProcessRunning(string processName)
    {
        return Process.GetProcessesByName(processName).Length != 0;
    }

Upvotes: 2

Related Questions