.net - Primitive values of WMI classes -
this complicated idea, , hope you'll bear me articulation difficult.
it seems wmi classes have primitive value can queried, while others not. has practical significance.
demo 1
take, instance, win32_processor class. primitive value, far can tell, value of instance's deviceid
column. allows querying, example, architecture (32 / 64-bitness) of running os tidy one-liner, jscript example:
var arch = getobject("winmgmts:root\\cimv2:win32_processor='cpu0'").addresswidth
in example, getobject
acts sort of select instance primitive value="cpu0"
, returns single instance, rather collection. works intended.
demo 2
on other hand, win32_operatingsystem class has no primitive value i've been able find. win32_processor
class deviceid
column, msdn documentation win32_operatingsystem
claims creationclassname
column table's key
field.
assume predictably, creationclassname=="win32_operatingsystem"
. therefore, 1 might infer similar one-liner written thusly:
var arch = getobject("winmgmts:root\\cimv2:win32_operatingsystem='win32_operatingsystem'").osarchitecture
however, results in error. trial-and-error attempts @ using other column values have equally met failure. appending .columname
between classname , =
results in syntax error well.
as far can tell, there's no way identify single instance of win32_operatingsystem
class without enumerating instances, if there 1 instance enumerate.
var wmi = getobject("winmgmts:"); var os = wmi.execquery("select osarchitecture win32_operatingsystem"); (var res = new enumerator(os); !res.atend(); res.movenext()) { var arch = res.item().osarchitecture; }
these lines can combined somewhat:
var os = getobject("winmgmts:").execquery("select osarchitecture win32_operatingsystem"); var arch = new enumerator(os).item().osarchitecture;
... it'd still nice query instance directly within win32_operatingsystem
without having enumerate irritatingly vestigial hierarchy.
the question
how can predict whether wmi class has primitive value can queried, , column contains value?
what you're looking 'key' property.
http://blogs.msdn.com/b/powershell/archive/2008/04/15/wmi-object-identifiers-and-keys.aspx
Comments
Post a Comment