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:25

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.

查看更多
你好瞎i
3楼-- · 2020-07-05 07:27

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
查看更多
做个烂人
4楼-- · 2020-07-05 07:31

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.

查看更多
萌系小妹纸
5楼-- · 2020-07-05 07:36

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
查看更多
家丑人穷心不美
6楼-- · 2020-07-05 07:37

To expand on the first answer, use this:

select AddressWidth from Win32_Processor where DeviceID="CPU0"
查看更多
仙女界的扛把子
7楼-- · 2020-07-05 07:37
登录 后发表回答