Determine the processorArchitecture of the running process from managed code


I discussed Figure out the bitness of a process and the ProcessorArchicture of the system back in July 2005.


If you just want to determine the processorArchitecture of the running process from managed code, there is an easier way in .Net framework 2.0.


C:\temp>more test.cs


using System;


using System.Reflection;


 


public class test


{


    public static void Main()


    {


        Console.WriteLine(typeof(System.Object).Assembly.GetName().ProcessorArchitecture);


    }


}


 


C:\temp>test


Amd64


This takes advantage of the fact that mscorlib.dll is a platform specific assembly in .Net framework v2.0.

Comments (3)

  1. jmstall says:

    Great tip. It looks like this saves me a pinvoke to kernel32!GetSystemInfo.

  2. oldnewthing says:

    But that’s an implementation detail. Maybe in the next version 3 of the framework, System.Object will be in a neutral assembly. Don’t rely on undocument side effects. Do it the right way.

  3. rape stories says:

    Best of the text i read about a problem.