Tuesday, January 5, 2010

Determining OS Bit-Level

With x64 computing quickly overtaking 32-bit environments a vast need has been created to know what bit-level on which a given OS is running.  Welcome back PowerShell and WMI

ONELINER

(gwmi win32_computersystem).SystemType
 code: copy : expand : collapse

EXPLANATION
Opening the Win32_ComputerSystem class gives us very useful information such as the mfg model, computer name, domain,...the list goes on.  What we are looking for is the OS architecture (bit-level).  We're able to retrieve this throught the SystemType property.  On a x64 OS it will return "x64-based PC", and "X86-based PC" for a 32-bit OS.

2 comments:

Anonymous said...

Are you sure about this?

I think you mean "What is the OS architecture?

This class also doewsn't tell yuo anything about teh word length of that teh OS is using which depends on what OS is installed. To determine OS you need to use Win32_OperatingSystem Class.

The SystemType will only return one of your two values for Intel Processors.

The current list is:
"X86-based PC"
"MIPS-based PC"
"Alpha-based PC"
"Power PC"
"SH-x PC"
"StrongARM PC"
"64-bit Intel PC"
"64-bit Alpha PC"
"Unknown"
"X86-Nec98 PC"

For processor architesture which is what I think you are after you need to look at: Win32_Processor. YOu will see that there are some 250 processor types. SOmeare 16 some 32 some 64. There are possibilities for larger word sizes which will be used for the MS HPC effort on 128 bit processors.

The Processor class is also necessary because it is possible to have processors of mixed tye on teh same bus although it rarely hpppens in consumer systems. The Win32_ComputerSystem class tracks the whole box and not it's architecture.

You should read through the WMI class documentation to see how all of this is put together.

Your blog looks good. Keep adding to it. There is never too much information only too little correct information.

Anonymous said...

Actually, SystemType does include x64-based PC. I'm not sure when it was added in and the documentation does not even show it exists, but it does.

Also, I specifically did not use the Win32_Processor because it shows the actual bit-level of the processor, not the system. So, it would be possible to return a 64-bit processor when the OS is still only running at 32-bit.

Thank you for your input and the challenge!

There is another WMI Class that could be used as well IF you are running Vista/2008 or higher. That is Win32_OperatingSystem that contains the OSArchitecture property as 32-bit or 64-bit. It is limited, so be careful.