检索 WMI Win32_Processor.Family 属性 的描述值而不是索引

Retrieving a descriptive value for WMI Win32_Processor.Family property instead of an index

下面的简单 VBS 示例从 WMI 中检索 CPU 标题、体系结构和系列:

s = ""
For Each Item In GetObject("winmgmts:{impersonationLevel=impersonate}!\.\Root\CIMV2").InstancesOf("Win32_Processor")
    s = s & "Caption = " & Item.Caption & vbCrLf
    s = s & "Architecture = " & Item.Architecture & vbCrLf
    s = s & "Family = " & Item.Family & vbCrLf
Next
WScript.Echo s

我的输出是:

Caption = Intel64 Family 6 Model 42 Stepping 7
Architecture = 9
Family = 198

我想要的是检索架构和系列的更多描述性值而不是索引。此类属性具有 Values 限定符,它指定 属性 的可能值列表,以及 ValueMap 限定符,它指定 Values 中相应字符串值的整数值。我用两个实用程序制作的屏幕截图显示了限定符:

WMI 代码创建器

WMI CIM 工作室

在最后一个屏幕截图中,您可以看到 Win32_Processor class、Architecture 属性、Values 限定符,其中包含六个字符串的数组:x86, MIPS, Alpha, PowerPC, ia64, x64它对应于 ValueMap 限定符中数组的索引:0, 1, 2, 3, 6, 9。但是,由于未知原因,以下代码未枚举在 WMI CIM Studio 中标记为已修改的限定符,例如 DescriptionValues

Set objClass = GetObject("winmgmts:{impersonationLevel=impersonate}!\.\root\CIMV2:Win32_Processor")
s = ""
For Each objQualifier In objClass.Properties_("Architecture").Qualifiers_
    s = s & objQualifier.Name & " = "
    If IsArray(objQualifier.Value) Then 
        s = s & "{" & Join(objQualifier.Value, ", ") & "}"
    Else
        s = s & objQualifier.Value
    End If
    s = s & vbCrLf
Next
WScript.Echo s

我试过运行它在x64和x86主机上,和它returns一样的输出,如下:

CIMTYPE = uint16
MappingStrings = {WMI}
read = True
ValueMap = {0, 1, 2, 3, 6, 9}

虽然我预期:

CIMTYPE = uint16
Description = The Architecture property specifies the processor architecture used by this platform. It returns one of the following integer values:
0 - x86
1 - MIPS
2 - Alpha
3 - PowerPC
6 - ia64
9 - x64
MappingStrings = {WMI}
read = True
ValueMap = {0, 1, 2, 3, 6, 9}
Values = {x86, MIPS, Alpha, PowerPC, ia64, x64}

我怎样才能获得资格赛?还有其他方法可以找回它们吗?

更新

我已经设法获得所有 属性 限定词,包括修改的,感谢 @Kul-Tigin 为我指明了正确的方向并提供了链接。访问限定符后,我从 class 中提取 ValuesValueMap 数组,并创建一种用于整数 属性 的转换 table oMap ] 值转换为相关字符串:

Const wbemFlagUseAmendedQualifiers = 131072
Set oService = GetObject("winmgmts:{impersonationLevel=impersonate}!\.\Root\CIMV2")
s = ""
For Each oInstance In oService.InstancesOf("Win32_Processor")
    For Each sName In Array("Caption", "Family")
        s = s & sName & " = " & oInstance.Properties_.Item(sName).Value & vbCrLf
    Next
Next
s = s & vbCrLf
Set oClass = oService.Get("Win32_Processor", wbemFlagUseAmendedQualifiers)
Set oProperty = oClass.Properties_.Item("Family")
aValues = oProperty.Qualifiers_.Item("Values")
aValueMap = oProperty.Qualifiers_.Item("ValueMap")
Set oMap = CreateObject("Scripting.Dictionary")
For i = 0 To UBound(aValues)
    oMap(aValueMap(i)) = aValues(i)
Next
For Each sKey In oMap
    s = s & sKey & " = " & oMap(sKey) & vbCrLf
Next
WScript.Echo s

我的输出如下:

Caption = Intel64 Family 6 Model 42 Stepping 7
Family = 198

1 = Other
2 = Unknown
3 = 8086
4 = 80286
5 = 80386
6 = 80486
7 = 8087
8 = 80287
9 = 80387
10 = 80487
11 = Pentium(R) brand
12 = Pentium(R) Pro
13 = Pentium(R) II
14 = Pentium(R) processor with MMX(TM) technology
15 = Celeron(TM)
16 = Pentium(R) II Xeon(TM)
17 = Pentium(R) III
18 = M1 Family
19 = M2 Family
24 = K5 Family
25 = K6 Family
26 = K6-2
27 = K6-3
28 = AMD Athlon(TM) Processor Family
29 = AMD(R) Duron(TM) Processor
30 = AMD29000 Family
31 = K6-2+
32 = Power PC Family
33 = Power PC 601
34 = Power PC 603
35 = Power PC 603+
36 = Power PC 604
37 = Power PC 620
38 = Power PC X704
39 = Power PC 750
48 = Alpha Family
49 = Alpha 21064
50 = Alpha 21066
51 = Alpha 21164
52 = Alpha 21164PC
53 = Alpha 21164a
54 = Alpha 21264
55 = Alpha 21364
64 = MIPS Family
65 = MIPS R4000
66 = MIPS R4200
67 = MIPS R4400
68 = MIPS R4600
69 = MIPS R10000
80 = SPARC Family
81 = SuperSPARC
82 = microSPARC II
83 = microSPARC IIep
84 = UltraSPARC
85 = UltraSPARC II
86 = UltraSPARC IIi
87 = UltraSPARC III
88 = UltraSPARC IIIi
96 = 68040
97 = 68xxx Family
98 = 68000
99 = 68010
100 = 68020
101 = 68030
112 = Hobbit Family
120 = Crusoe(TM) TM5000 Family
121 = Crusoe(TM) TM3000 Family
122 = Efficeon(TM) TM8000 Family
128 = Weitek
130 = Itanium(TM) Processor
131 = AMD Athlon(TM) 64 Processor Family
132 = AMD Opteron(TM) Family
144 = PA-RISC Family
145 = PA-RISC 8500
146 = PA-RISC 8000
147 = PA-RISC 7300LC
148 = PA-RISC 7200
149 = PA-RISC 7100LC
150 = PA-RISC 7100
160 = V30 Family
176 = Pentium(R) III Xeon(TM)
177 = Pentium(R) III Processor with Intel(R) SpeedStep(TM) Technology
178 = Pentium(R) 4
179 = Intel(R) Xeon(TM)
180 = AS400 Family
181 = Intel(R) Xeon(TM) processor MP
182 = AMD AthlonXP(TM) Family
183 = AMD AthlonMP(TM) Family
184 = Intel(R) Itanium(R) 2
185 = Intel Pentium M Processor
190 = K7
200 = IBM390 Family
201 = G4
202 = G5
203 = G6
204 = z/Architecture base
250 = i860
251 = i960
260 = SH-3
261 = SH-4
280 = ARM
281 = StrongARM
300 = 6x86
301 = MediaGX
302 = MII
320 = WinChip
350 = DSP
500 = Video Processor

我也在另一台电脑上试过代码:

Caption = AMD64 Family 21 Model 56 Stepping 1
Family = 72

...

关于MSDN about Standard Qualifiers用法的细节很少:

ValueMap
This qualifier can be used alone or in combination with the Values qualifier. When used in combination with the Values qualifier, the location of the value in the ValueMap array provides the location of the corresponding entry in the Values array. Use the ValueMap qualifier only with string and integer values. The syntax for representing an integer value in the value map array is [+|=]digit[*digit]. The content, maximum number of digits, and represented value are constrained by the type of the associated property. For example, uint8 may not be signed, must be less than four digits, and must represent a value less than 256.

Values
This property also specifies an array of string values to be mapped to an enumeration property. This qualifier can be applied to either an integer property or a string property, and the mapping can be implicit or explicit. If the mapping is implicit, integer or string property values represent ordinal positions in the Values array. If the mapping is explicit, the property must be an integer, and valid property values are listed in the array defined by the ValueMap qualifier. For more information, see Value Map.
If a ValueMap qualifier is not present, the Values array is indexed (zero-relative) by using the value in the associated property, method return type, or method parameter. If a ValueMap qualifier is present, the values index is defined by the location of the property value in the value map.

现在我无法检索适当的字符串,因为在 ValueMap 限定符中既没有 198 也没有 72 这样的索引。

答案是,Values/ValueMap限定符字符串table不完整,无法使用。如果您想将每个索引映射到字符串值,您必须自己创建这样的 table。

Win32_ProcessorclassFamily属性的值来自Processor InformationSMBIOS structure. Values are defined by specification(最新截至 2018 年 1 月的文档),第 46 页的 table 包含所需的字符串:

198 - Intel® Core™ i7 processor

72 - AMD A-Series Processor

使用此数据,您可以创建字符串 table 并维护它,因为新的处理器类型将在新的 SMBIOS 版本中引入。

可以找到 C++ 枚举形式的类似数据 here