如何通过WMI确定操作系统平台?
我试图弄清楚 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(13)
如果您需要操作系统架构而不是处理器,并且您确信自己没有 64 位 Windows 5.x 系统,则可以使用此方法:
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:
试试这个:
Try this:
您使用的简单 WMI 查询确实会返回计算机中每个物理 CPU 的结果。如果您有单处理器、多核 CPU,它只会返回一个结果。我们可以放心地假设计算机至少有一个 CPU,因此我们只使用 CPU0 中的信息。
仅选择 64 位操作系统...
仅选择 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...
To select only 32-bit operating systems...
使用以下 WMI 类和属性 - 这应该适用于
Technet:
Use the following WMI class and property - This should work on 2003/XP and Win7/2008R2
From Technet:
经过一段时间的搜索和测试,我想出了一个“修复/答案”,尽管这并不完全是我所希望的。通过注册表执行查询似乎在我实验室中的所有 Win2k3 和 Windows 版本中都是一致的。 Win2k8.这是我从中提取信息的地方:
它显示 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:
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.
要扩展第一个答案,请使用:
To expand on the first answer, use this:
(未经测试),但也许:
CIM_Processor 类 (AddressWidth)
(Not tested), but maybe:
CIM_Processor Class (AddressWidth)
在VBS中:
In VBS:
批量中
In batch
您可以使用 wmic 尝试以下语法来确定平台:
You can try the syntax below using wmic to determine the platform:
我知道这已经过时了,我将来会将其发布给任何人。尝试查看我的脚本。它是用 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.
环境变量“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'.
这并不完全是您所要求的,但我只是在 WMI 查询(组策略首选项定位)中使用了它,并且到目前为止它似乎有效:
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: