Freigeben über


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

  • Anonymous
    March 14, 2006
    Great tip. It looks like this saves me a pinvoke to kernel32!GetSystemInfo.
  • Anonymous
    March 14, 2006
    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.
  • Anonymous
    June 01, 2006
    Best of the text i read about a problem.