Inside and Out…

An attempt to understand technology better…

Adding process enumeration support in Rotor v1.0

Posted by Gaurav Khanna on September 5, 2005

Share Source CLI, better known as Rotor, is one of the best ways to understand how .NET Framework works. And with the source code availability as part of Rotor distribution, its an excellent academic/hobby interest – you can extend it by adding more functionality, or modify the existing one and see how it behaves.

Yesterday, I went about doing the same. One of the functionality which I found missing in Rotor is that of enumerating system process list. .NET Framework’s System.Diagnostics.Process class has methods, like GetProcesses, that allow you to do the same.

So, I went about implementing GetProcesses method overloadsin System.Diagnostics.Process class that allow me to enumerate process list on the local machine only. This required modification in the Platform Adaptation Layer (PAL) of Rotor. Since, I just have it running on Win32 for the moment, I modified the Win32 PAL to implement the support via ToolHelpAPI. Now, on a Windows system, its possible to enumerate the system process list using Rotor, as exemplified by the snippet below:

You can download the updated source files for Rotor v1.0 from http://www.wintoolzone.com/showpage.aspx?url=rotor.aspx. The zipped archive contains Changes for Process Enumeration.txt that indicates where the updated files need to be copied. Once done, rebuild Rotor to get the changes into effect.

using System; 
using System.Diagnostics;

public class EnumProcess
{
    public static void Main()
    {
        Process[] arrProcess = Process.GetProcesses();
        if (arrProcess == null)
        {
            Console.WriteLine("Unable to get process list!");
            return;
        }

        Console.WriteLine("{0} processes enumerated.", arrProcess.Length);

        foreach (Process proc in arrProcess)
            Console.WriteLine("Process ID {0}, Handle: {1}", proc.Id, proc.Handle);
    }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: