How to determine OS Platform with WMI?

后端 未结 13 3572
無奈伤痛
無奈伤痛 2021-02-20 03:46

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 though

相关标签:
13条回答
  • 2021-02-20 04:29

    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
    
    0 讨论(0)
  • 2021-02-20 04:30

    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"
    
    0 讨论(0)
  • 2021-02-20 04:32

    To expand on the first answer, use this:

    select AddressWidth from Win32_Processor where DeviceID="CPU0"
    
    0 讨论(0)
  • 2021-02-20 04:35

    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.

    0 讨论(0)
  • 2021-02-20 04:35

    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.

    0 讨论(0)
  • 2021-02-20 04:38

    Try this:

    wmic cpu get DataWidth /format:list
    
    0 讨论(0)
提交回复
热议问题