11

I am trying to figure out if there is a location in WMI that will return the OS Architecture (i.e. 32-bit or 64-bit) that will work across "all" versions of Windows. I thought I had figured it out looking at my Win2k8 system when I found the following:

 Win32_OperatingSystem / OSArchitecture

I was wrong. It doesn't appear that this field exists on Win2k3 systems. Argh!

So, is anyone aware of another field in WMI that "is" the same across server versions? If not, what about a registry key that is the same? I am using a tool that only allows me to configure simple field queries, so I cannot use a complex script to perform.

Any help would be greatly appreciated.

Chathura Buddhika
  • 2,067
  • 1
  • 21
  • 35
user172286
  • 131
  • 1
  • 1
  • 5

13 Answers13

6

If you need the Operating System architecture as opposed to the processor, this works if you're confident you have no 64 bit Windows 5.x systems:

Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)  
on error resume next  

For Each objItem in colItems  
    Ver = objItem.Version  
    OSname = split(objItem.Name,"|")  
    Arch = "32-bit"  
    if left(Ver,3) >= 6.0 then    ' 5.x doesn't support this property  
        Arch = objItem.OSArchitecture  
    end if  
Next  
wscript.echo " OS Version: " & Ver & " {" & trim(OSname(0)) & " " & Arch & "}"
Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438
gudbarnone
  • 61
  • 1
  • 2
5

The simple WMI query that you used does indeed return a result for every physical CPU in the computer. It will only return one result if you have a single processor, multiple core CPU. We can safely assume the computer has atleast one CPU, so lets just use the information from CPU0.

To select only 64-bit operating systems...

select * from Win32_Processor where DeviceID="CPU0" and AddressWidth="64"

To select only 32-bit operating systems...

select * from Win32_Processor where DeviceID="CPU0" and AddressWidth="32"
Andrei Sfat
  • 8,440
  • 5
  • 49
  • 69
Thomas York
  • 59
  • 1
  • 2
  • 1
    +1 b/c this works, but I still prefer `Win32_OperatingSystem.OSArchitecture`, creature of habit I suppose. – MDMoore313 Jan 24 '13 at 18:57
5

Try this:

wmic cpu get DataWidth /format:list
Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
3

Use the following WMI class and property - This should work on 2003/XP and Win7/2008R2

ROOT\CIMV2\Win32_Processor
AddressWidth

From Technet:

On a 32-bit operating system, the value is 32 and on a 64-bit operating system it is 64. This property is inherited from CIM_Processor.

Juan Sosa
  • 5,262
  • 1
  • 35
  • 41
2

After awhile of searching and testing, I've come up with a "fix/answer" although it's not exactly what I was hoping for. Performing the query from via the Registry appears to be consistent across all the version I have in my lab for Win2k3 & Win2k8. Here's where I am pulling the information from:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment

KEY: PROCESSOR_ARCHITECTURE

It displays x86 or AMD64. It's not perfect, but at least it gives me the proper answer every time.

Still, if anyone knows a consistent 'Class' or Registry key that will output 32/64, 32-bit/64-bit, or X86/X64, I would greatly appreciate the information.

phihag
  • 278,196
  • 72
  • 453
  • 469
user172286
  • 131
  • 1
  • 1
  • 5
  • 1
    Any reason you're querying ControlSet001 instead of CurrentControlSet? Mine's working fine using the latter. – Daniel.S Nov 30 '12 at 01:25
  • @user172286 `CurrentControlSet` would be definitely better. I have one Windows computer where the registry key `HKLM\SYSTEM\Select` has the registry double word `Current` with value `3` and `LastKnownGood` with value `2` and where exists now only `ControlSet003` being `CurrentControlSet` and `ControlSet002`. This has been caused because of starting Windows with `ControlSet001` had failed years ago and was deleted by Windows after copying last known good `ControlSet002` to `ControlSet003`. – Mofi Jan 27 '19 at 08:54
2

To expand on the first answer, use this:

select AddressWidth from Win32_Processor where DeviceID="CPU0"
TMassa
  • 21
  • 1
0

You can try the syntax below using wmic to determine the platform:

wmic path win32_processor where deviceid="cpu0" get Addresswidth
rmtheis
  • 5,992
  • 12
  • 61
  • 78
Joe
  • 1
0

In batch

IF EXIST "%PROGRAMFILES% (x86)" goto 64BIT
goto 32BIT

:64BIT
echo tantalana a 64 bit
goto FINE

:32BIT
echo tantalaniccia a 32 bit
goto FINE

:FINE
echo ciao
0

(Not tested), but maybe:

CIM_Processor Class (AddressWidth)

ChristopheD
  • 112,638
  • 29
  • 165
  • 179
  • Christophe, That does appear to return the right architecture. However, if there is more then one (1) CPU, it appears that a simply WMI query returns the 'AddressWidth' for every CPU. If you have any other thoughts, they would be greatly appreciated! Thanks much!!! Cheers... Cary – user172286 Sep 11 '09 at 22:06
0

In VBS:

On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Set objWMIService = GetObject("winmgmts:\\.\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_Processor", "WQL", _
                                          wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
   WScript.Echo "AddressWidth: " & objItem.AddressWidth
Next
Michael Mrozek
  • 169,610
  • 28
  • 168
  • 175
  • 1
    François, Thanks for the reply! Unfortuantely, I was trying to find a "simple" WMI query and not actually build a query. In other words, I wanted to kind a single entry within WMI that would list the processor type for use with some special software. I can't generate a query, I can only provide the location within WMI to find the data. Thanks! Cheers... Cary – user172286 May 20 '10 at 22:25
0

The environment variable 'PROCESSOR_ARCHITECTURE' is all that is needed. Just like the registry call this will return either 'AMD64' or 'x86'.

Tony D
  • 1
  • This is incorrect if an x86 application running on 64-bit Windows in 32-bit environment is accessing environment variable `PROCESSOR_ARCHITECTURE` as Microsoft documented on page about [WOW64 Implementation Details](https://learn.microsoft.com/en-us/windows/desktop/WinProg64/wow64-implementation-details). – Mofi Dec 30 '18 at 20:36
0

This isn't exactly what you asked for, but I just used this in a WMI query (Group Policy Preference targeting) and it appears to work thus far:

SELECT * FROM Win32_ComputerSystem WHERE SystemType="x64-based pc"
deoren
  • 399
  • 3
  • 6
0

I know this is old, I am posting this for anyone in the future. Try looking at my script. It's written in BATCH and uses WMIC if it is on the computer but does not need it in order to determine whether the OS is running a 32 bit of 64 bit OS.

Konrad Viltersten
  • 36,151
  • 76
  • 250
  • 438