How to determine OS Platform with WMI?

后端 未结 13 3573
無奈伤痛
無奈伤痛 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:39

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

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

    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.

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

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

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

    (Not tested), but maybe:

    CIM_Processor Class (AddressWidth)

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

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

    wmic path win32_processor where deviceid="cpu0" get Addresswidth
    
    0 讨论(0)
提交回复
热议问题