用VBS判断操作系统是32位(x86)还是64位(x64)

标签: , , , ,

突然想到这个问题,虽然不知道为什么要用 VBS 判断当前系统是32位还是64位,但是也许以后会用到也说不定。用到 WMI 的 Win32_ComputerSystem 类的 SystemType 属性。

Function X86orX64()
    'Author: Demon
    'Date: 2011/11/12
    'Website: https://demon.tw
    On Error Resume Next
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
    
    For Each objItem in colItems
        If InStr(objItem.SystemType, "86") <> 0 Then
            X86orX64 = "x86"
        ElseIf InStr(objItem.SystemType, "64") <> 0 Then
            X86orX64 = "x64"
        Else
            X86orX64 = objItem.SystemType
        End If
    Next
    
End Function

WScript.Echo X86orX64()

参考链接:Win32_ComputerSystem

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. Switch 无法启动软件。 请在HOME菜单中再试一次。
  2. 3DS导出正版卡带存档并导入到CIA
  3. Python,又见Python
  4. 批处理技术内幕:ECHO命令
  5. VBS文件拖拽的个数限制(无法执行 – 参数列表过长)

4 条评论 发表在“用VBS判断操作系统是32位(x86)还是64位(x64)”上

  1. 陈旭华说道:

  2. 陈旭华说道:

    我想请教下 vbs如何获取系统版本 比如判断xp或win7

  3. VampireDX说道:

    我想请教,我想写一个脚本,运行某个程序,但那时x86和x64的路径不一样,所以我要先判断,然后运行程序,但是你这个脚本有一个返回值,如果做到运行以后,就不要返回值了呢,如下,请帮我修改,谢谢。
    Set ws = CreateObject(“WScript.Shell”)

    Function X86orX64()

    On Error Resume Next
    strComputer = “.”
    Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
    Set colItems = objWMIService.ExecQuery(“Select * from Win32_ComputerSystem”,,48)

    For Each objItem in colItems
    If InStr(objItem.SystemType, “86”) 0 Then
    ws.Run “””C:\Program Files\xxx\xxx\setup.exe”””,,True
    ElseIf InStr(objItem.SystemType, “64”) 0 Then
    ws.Run “””C:\Program Files (x86)\xxx\xxx\setup.exe”””,,True
    Else
    X86orX64 = objItem.SystemType
    End If

    NEXT

    End Function

    WScript.Echo X86orX64()

  4. Yu2n说道:

    ' Is64OS() By Yu2n
    ' 示例:If Is64OS() = True Then ...
    ' Ps: 已堕落到不执着于 “纯” VBS
    Function Is64OS()
      On Error Resume Next
      Is64OS = False
      Set wso = CreateObject("WScript.Shell")
      If wso.Run("cmd /c set ProgramFiles|find /i ""x86"" ",1,True) = 0 Then
        If Err.Number = 0 Then Is64OS = True
      End If
    End Function

陈旭华 留下回复