ATTENTION: I've decided to put the upgrade on hold due to a compatibility issue of our server environment with the latest CS installer package. CS 2008 now requires SQL Server 2005 as the backend DB but our database server currenlty has SQL Server 2000 installed on it. I'll resume the upgrade once I figure out when Telligent is releasing a patch to the schema compatibility issue. For now, we will continue to use the old version of CS while waiting for the said patch. If you have any questions about this process, please don't hesitate to post them on our forums and I'll answer them as soon as I can. Thanks for your patience and support guys! I'll let you know as soon as this is resolved. - Keith Rull

How To: Check if there are processes that are running using .NET

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

Comments

bonskijr wrote re: How To: Check if there are processes that are running using .NET
on 03-09-2007 9:23 PM

great example, currently my tool of choice for checking managed application is ProcessExplorer.

lamia wrote re: How To: Check if there are processes that are running using .NET
on 03-11-2007 10:13 PM

Nice! I like stuff like this! They always get to be useful for you sometime. Uhmmm.. How do I bookmark this post?

Joben.Rara.blogs(".NET") wrote How To: Check if there are processes that are running using .NET (using PowerShell)
on 03-16-2007 12:12 PM

Keith posted a console app he created to determine the processes that are running .NET applications.

Add a Comment

(required)  
(optional)
(required)  
Remember Me?

Enter the numbers above:

Copyright DevPinoy 2005-2008