如何通过WMI确定操作系统平台?

发布于 2024-08-05 02:28:30 字数 322 浏览 7 评论 0原文

我试图弄清楚 WMI 中是否有一个位置将返回可在“所有”版本的 Windows 上工作的操作系统架构(即 32 位或 64 位)。当我发现以下内容时,我以为我已经弄清楚了我的Win2k8系统:

 Win32_OperatingSystem / OSArchitecture

我错了。 Win2k3 系统上似乎不存在该字段。啊!

那么,有人知道 WMI 中的另一个字段在服务器版本之间“是”相同的吗?如果不是,那么相同的注册表项又如何呢?我使用的工具只允许我配置简单的字段查询,因此我无法使用复杂的脚本来执行。

任何帮助将不胜感激。

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 thought I had figured it out looking at my Win2k8 system when I found the following:

 Win32_OperatingSystem / OSArchitecture

I was wrong. It doesn't appear that this field exists on Win2k3 systems. Argh!

So, is anyone aware of another field in WMI that "is" the same across server versions? If not, what about a registry key that is the same? I am using a tool that only allows me to configure simple field queries, so I cannot use a complex script to perform.

Any help would be greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

顾铮苏瑾 2024-08-12 02:28:30

如果您需要操作系统架构而不是处理器,并且您确信自己没有 64 位 Windows 5.x 系统,则可以使用此方法:

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 & "}"

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 & "}"
魂ガ小子 2024-08-12 02:28:30

试试这个:

wmic cpu get DataWidth /format:list

Try this:

wmic cpu get DataWidth /format:list
快乐很简单 2024-08-12 02:28:30

您使用的简单 WMI 查询确实会返回计算机中每个物理 CPU 的结果。如果您有单处理器、多核 CPU,它只会返回一个结果。我们可以放心地假设计算机至少有一个 CPU,因此我们只使用 CPU0 中的信息。

仅选择 64 位操作系统...

select * from Win32_Processor where DeviceID="CPU0" and AddressWidth="64"

仅选择 32 位操作系统...

select * from Win32_Processor where DeviceID="CPU0" and AddressWidth="32"

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"
半衾梦 2024-08-12 02:28:30

使用以下 WMI 类和属性 - 这应该适用于

ROOT\CIMV2\Win32_Processor
AddressWidth

Technet

在 32 位操作系统上,该值为 32,在 64 位操作系统上,该值为 32
操作系统是 64。该属性继承自
CIM_处理器。

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.

旧瑾黎汐 2024-08-12 02:28:30

经过一段时间的搜索和测试,我想出了一个“修复/答案”,尽管这并不完全是我所希望的。通过注册表执行查询似乎在我实验室中的所有 Win2k3 和 Windows 版本中都是一致的。 Win2k8.这是我从中提取信息的地方:

HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Session Manager\Environment

KEY: PROCESSOR_ARCHITECTURE

它显示 x86 或 AMD64。它并不完美,但至少每次都给我正确的答案。

尽管如此,如果有人知道将输出 32/64、32 位/64 位或 X86/X64 的一致“类”或注册表项,我将非常感谢这些信息。

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.

掐死时间 2024-08-12 02:28:30

要扩展第一个答案,请使用:

select AddressWidth from Win32_Processor where DeviceID="CPU0"

To expand on the first answer, use this:

select AddressWidth from Win32_Processor where DeviceID="CPU0"
只有一腔孤勇 2024-08-12 02:28:30

(未经测试),但也许:

CIM_Processor 类 (AddressWidth)

(Not tested), but maybe:

CIM_Processor Class (AddressWidth)

请帮我爱他 2024-08-12 02:28:30

在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

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
烟凡古楼 2024-08-12 02:28:30

批量中

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

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
演多会厌 2024-08-12 02:28:30

您可以使用 wmic 尝试以下语法来确定平台:

wmic path win32_processor where deviceid="cpu0" get Addresswidth

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

wmic path win32_processor where deviceid="cpu0" get Addresswidth
甚是思念 2024-08-12 02:28:30

我知道这已经过时了,我将来会将其发布给任何人。尝试查看我的脚本。它是用 BATCH 编写的,如果计算机上有 WMIC,则使用 WMIC,但不需要它来确定操作系统是否正在运行 32 位或 64 位操作系统。

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.

娇纵 2024-08-12 02:28:30

环境变量“PROCESSOR_ARCHITECTURE”就是所需要的。就像注册表调用一样,这将返回“AMD64”或“x86”。

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

家住魔仙堡 2024-08-12 02:28:30

这并不完全是您所要求的,但我只是在 WMI 查询(组策略首选项定位)中使用了它,并且到目前为止它似乎有效:

SELECT * FROM Win32_ComputerSystem WHERE SystemType="x64-based pc"

This isn't exactly what you asked for, but I just used this in a WMI query (Group Policy Preference targeting) and it appears to work thus far:

SELECT * FROM Win32_ComputerSystem WHERE SystemType="x64-based pc"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文