How can I use VBScript to determine whether I am running a 32-bit or 64-bit Windows OS?

前端 未结 8 490
死守一世寂寞
死守一世寂寞 2020-12-25 08:46

How do i detect the bitness (32-bit vs. 64-bit) of the Windows OS in VBScript?

I tried this approach but it doesn\'t work; I guess the (x86) is causing some problem

相关标签:
8条回答
  • 2020-12-25 09:47
    ' performance should be good enough
    ' Example usage for console:
    ' CSript //NoLogo *ScriptName*.vbs
    ' If ErrorLevel 1 Echo.Win32
    ' VBScript:
    On Error Resume Next
    Const TargetWidth = 32
    Set WMI = GetObject("winMgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
    Set Query = WMI.ExecQuery("SELECT AddressWidth FROM Win32_Processor")
    For Each Item in Query
      If Item.AddressWidth = TargetWidth Then
        WScript.Quit 1
      End If
    Next
    WScript.Quit 0
    
    0 讨论(0)
  • 2020-12-25 09:49

    WMIC queries may be slow. Use the environment strings:

    Function GetOsBits()
       Set shell = CreateObject("WScript.Shell")
       If shell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%") = "AMD64" Then
          GetOsBits = 64
       Else
          GetOsBits = 32
       End If
    End Function
    
    0 讨论(0)
提交回复
热议问题