How to determine OS Platform with WMI?

2020-07-05 06:47发布

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.

13条回答
我想做一个坏孩纸
2楼-- · 2020-07-05 07:38

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.

查看更多
▲ chillily
3楼-- · 2020-07-05 07:39

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

wmic path win32_processor where deviceid="cpu0" get Addresswidth
查看更多
劳资没心,怎么记你
4楼-- · 2020-07-05 07:42

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"
查看更多
男人必须洒脱
5楼-- · 2020-07-05 07:46

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"
查看更多
等我变得足够好
6楼-- · 2020-07-05 07:46

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

查看更多
倾城 Initia
7楼-- · 2020-07-05 07:50

Try this:

wmic cpu get DataWidth /format:list
查看更多
登录 后发表回答