I was running a test on my Web Server today when a friend of mine IMed me about an interesting question about .NET. He was a new programmer for this company and the old developer that he replaced was running production(oh my) applications right of his desktop. The IT manager was getting worried because they dont have a list of applications that the old guy did because the old developer didnt do any turnover(he was fired =)) and alot of the apps that he did were essential to the business(the company was a small accounting firm). So my friend asked me if theres a way to figure out which applications are running using managed code so that they could check the application and move it to a more secure and dependable server.
I know i could do this using a console command
c:\ tasklist /fi "modules eq mscoree.dll"
But they wanted more information about the file so i decided build him a small console app. The code below checks to see if there are any process that is using Managed Code and displays what .NET version it is using.
using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Diagnostics;
namespace KeithRull.WhosUsingDotNet
{
/// <summary>
/// A code snippet that checks what applications are running .NET
/// and tells what version they are using.
/// </summary>
class Program
{
/// <summary>
/// Microsoft .NET Runtime Common Language Runtime
/// </summary>
const string STR_Mscorwksdll = "mscorwks.dll";
public static void Main()
{
// Create the headers
Console.WriteLine("{0,-40} {1}", "Process Name", ".NET version");
Console.WriteLine("{0}", "--------------------------------------------------------");
// Get a list of running processes
System.Diagnostics.Process[] runningProcesses = Process.GetProcesses();
// Initialize a counter
int manageApplications = 0;
// Iterate on all running processes
foreach (Process process in runningProcesses)
{
try
{
// iterate thru each module in the process
foreach (ProcessModule processModule in process.Modules)
{
// Get the name of the module
string processModuleName = processModule.ModuleName.ToLower();
// Check if the process is using the .NET Runtime Library
if (processModuleName.Equals(STR_Mscorwksdll))
{
// Get the name of the process
string processName = process.ProcessName;
// Get the .NET file version
string fileVersion = processModule.FileVersionInfo.ProductVersion;
// Print the result to the console
Console.WriteLine("{0,-40} {1}", processName, fileVersion);
// Add 1 to our counter
manageApplications += 1;
}
}
}
catch (Win32Exception wex)
{
// Exceptions? eh, nothing to do here.
}
}
// Display a report
Console.WriteLine();
Console.WriteLine("{0}", "--------------------------------------------------------");
Console.WriteLine("Processes Found: {0} | Process Running .NET: {1}", runningProcesses.Length, manageApplications);
Console.WriteLine("{0}", "--------------------------------------------------------");
//Pause
Console.ReadLine();
}
}
}
Here's a screenshot

Problem Solved! =)
Posted
Mar 09 2007, 03:51 PM
by
keithrull