如何使用 VBScript 确定我运行的是 32 位还是 64 位 Windows 操作系统? [英] How can I use VBScript to determine whether I am running a 32-bit or 64-bit Windows OS?

查看:24
本文介绍了如何使用 VBScript 确定我运行的是 32 位还是 64 位 Windows 操作系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 VBScript 中检测 Windows 操作系统的位数(32 位与 64 位)?

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

我尝试过这种方法,但它不起作用;我猜 (x86) 导致了一些检查文件夹的问题..

I tried this approach but it doesn't work; I guess the (x86) is causing some problem which checking for the folder..

还有其他选择吗?

progFiles="c:program files" & "(" & "x86" & ")"

set fileSys=CreateObject("Scripting.FileSystemObject")

If fileSys.FolderExists(progFiles) Then    
   WScript.Echo "Folder Exists"    
End If

推荐答案

可以查询PROCESSOR_ARCHITECTURE.描述 此处,您必须添加一些额外的检查,因为对于任何 32 位进程,PROCESSOR_ARCHITECTURE 的值将是 x86,即使它在 64 位上运行操作系统.在这种情况下,变量 PROCESSOR_ARCHITEW6432 将包含操作系统位数.MSDN 中的更多详细信息.

You can query the PROCESSOR_ARCHITECTURE. A described here, you have to add some extra checks, because the value of PROCESSOR_ARCHITECTURE will be x86 for any 32-bit process, even if it is running on a 64-bit OS. In that case, the variable PROCESSOR_ARCHITEW6432 will contain the OS bitness. Further details in MSDN.

Dim WshShell
Dim WshProcEnv
Dim system_architecture
Dim process_architecture

Set WshShell =  CreateObject("WScript.Shell")
Set WshProcEnv = WshShell.Environment("Process")

process_architecture= WshProcEnv("PROCESSOR_ARCHITECTURE") 

If process_architecture = "x86" Then    
    system_architecture= WshProcEnv("PROCESSOR_ARCHITEW6432")

    If system_architecture = ""  Then    
        system_architecture = "x86"
    End if    
Else    
    system_architecture = process_architecture    
End If

WScript.Echo "Running as a " & process_architecture & " process on a " _ 
    & system_architecture & " system."

这篇关于如何使用 VBScript 确定我运行的是 32 位还是 64 位 Windows 操作系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆