It's not 100% complete, see notes at the bottom.
Code: Select all
' see http://msdn.microsoft.com/en-us/library/aa393650(VS.85).aspx
' http://msdn.microsoft.com/en-us/library/aa384827(v=VS.85).aspx
' http://technet.microsoft.com/en-us/library/ee156571.aspx
'ModelCorrespondence Data type: string array
' Applies to: properties
'Set of values that indicate correspondence between an object's
'property and other properties in the CIM schema.
'The default is NULL.
'Object properties are identified using the following syntax.
'<schema name> "_" <class or association name> "." <property name>
option explicit
dim strComputer
strComputer = "."
dim strQual
strQual = vbCRLF
call EnumNameSpaces("root")
strQual = Join(SortArray(Split(strQual,vbCRLF)),vbCRLF)
wscript.echo strQual
sub EnumNameSpaces(strNameSpace)
dim objWMIService,colNameSpaces,objNameSpace
' On Error Resume next
wscript.echo "**********************************************************"
wscript.echo strNameSpace
call ListClasses(strNameSpace)
set objWMIService=GetObject( _
"winmgmts:{impersonationLevel=impersonate}\\" & _
strComputer & "\" & strNameSpace)
set colNameSpaces = objWMIService.InstancesOf("__NAMESPACE")
for each objNameSpace in colNameSpaces
if strNameSpace & "\" & objNameSpace.Name <> "root\directory" then
call EnumNameSpaces(strNameSpace & "\" & objNameSpace.Name)
else
wscript.echo "SKIP root\directory"
end if
next
end sub
'AMENDMENT=True
'LOCALE=1033
sub ListClasses(strNameSpace)
dim objWMIService,objclass,objClassProperty,objQualifier
set objWMIService = GetObject( _
"winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\" & strNameSpace)
for each objclass in objWMIService.SubclassesOf()
wscript.echo " Class " & objClass.Path_.Class
call DumpProp(objClass,"Class")
call DumpMethod(objClass)
next
set objWMIService = Nothing
end sub
function Shorten(str,lmax) ' to show descriptions (DBG?)
dim wl,ws
wl = Len(str)
ws = Left(str,lmax)
if wl > Len(ws) then
Shorten = ws & "..."
else
Shorten = str
end if
end function
' Qualifier "ValueMap" corresponds to qualifier "Values" or "DefineValues" or both
' also "ValueDescriptions" may be present
' cpp_quote - looks like C++ quotation - should go to description
' Should return a record:
' - name
' - type
' - description
' - other comments, like /* Key=true */
' - enumeration functions
' -
'=================================
'QLF:CIMTYPE=uint64
'QLF:CounterType=1073741824
'QLF:PerfDefault=True
'QLF:read=True
'QLF:WmiDataId=449
'QLF:CIMTYPE
'QLF:CIM_Key=True
'QLF:CIMTYPE=string
'QLF:MaxLen=256
'QLF:Propagated=CIM_System.Name
'QLF:read=True
'QLF:not_null=True
'/*Class Property*/ SettingID: string
'QLF:MaxLen=256
'QLF:Override=SettingId
'QLF:read=True
' /*Class Property*/ Arg4: uint64
' QLF:DisplayInHex=True
' QLF:read=True
' QLF:WmiDataId=9
function CutCRLF(str)
if Right(str,Len(vbCRLF)) = vbCRLF then
CutCRLF = Left(str,Len(str) - Len(vbCRLF))
else
CutCRLF = str
end if
end function
function NmOpt(opt,val)
if TypeName(val) <> "Boolean" then
'wscript.echo "+++++ " & opt & "TN=" & TypeName(val)
'wscript.echo "+++++ E=" & IsEmpty(val)
'wscript.echo "+++++ N=" & IsNull(val)
'wscript.echo "+++++ A=" & IsArray(val)
'wscript.echo "+++++ O=" & IsObject(val)
if IsArray(val) then
NmOpt = Opt & "=" & Join(val," ")
else
NmOpt = Opt & "=" & val
end if
exit function
end if
if val then
NmOpt = opt
else
NmOpt = "Not-" & opt
end if
end function
function DumpQual(obj,param,name)
dim objQual,wout,wqlf,wrslt
dim wval,wmap,wdef,wk,welm,wdscr,ws,woname,wf,wopt,wopt2,wsmap
wrslt = ""
wout = ""
wqlf = ""
wval = Null
wf = ""
wopt = ""
wopt2 = ""
wsmap = ""
woname = obj.Name
for each objQual in obj.Qualifiers_
select case Lcase(objQual.Name)
case "cimtype"
if objQual.Name <> "CIMTYPE" then
wscript.echo "ERROR on CIMTYPE"
end if
case "values"
wval = objQual.Value
case "valuemap"
wmap = objQual.Value
case "definevalues"
wdef = objQual.Value
case "valuedescriptions"
wdscr = objQual.Value
case "description"
wout = wout & Shorten(StrArr(objQual.Value,vbCRLF & " DSCR:"),50) & vbCRLF
case "displayname"
wout = wout & " SHOW:""" & objQual.Value & """"
case "bitvalues"
wout = wout & StrArr(objQual.Value," BITS:") & vbCRLF
case "mappingstrings"
if VarType(objQual.Value) = (vbVariant + vbArray) then
wsmap = wsmap & "MAP:" & _
"""" & Join(objQual.Value,""",""") & """" & vbCRLF
else
wsmap = wsmap & "MAP:" & _
"(""" & Replace(objQual.Value,"|",""",""") & """)" & vbCRLF
end if
case "units"
wopt = wopt & "UNITS:" & objQual.Value & ";"
case "subtype"
wopt = wopt & "SUBTYPE:" & objQual.Value & ";"
case "maxlen"
wopt = wopt & "MaxLen=" & objQual.Value & ";"
case "override"
wopt = wopt & "Override=" & objQual.Value & ";"
case "arraytype"
wopt = wopt & "ArrayType=" & objQual.Value & ";"
case "key"
wopt = wopt & NmOpt("Key",objQual.Value) & ";"
case "cim_key"
wopt = wopt & NmOpt("CIM_Key",objQual.Value) & ";"
case "write"
wopt = wopt & NmOpt("Write",objQual.Value) & ";"
case "read"
wopt = wopt & NmOpt("Read",objQual.Value) & ";"
case "template"
wopt = wopt & NmOpt("Template",objQual.Value) & ";"
case "deprecated"
wopt = wopt & NmOpt("Deprecated",objQual.Value) & ";"
case "static"
wopt = wopt & NmOpt("Static",objQual.Value) & ";"
case "implemented"
wopt = wopt & NmOpt("Implemented",objQual.Value) & ";"
case "experimental"
wopt = wopt & NmOpt("Experimental",objQual.Value) & ";"
case "not_null"
wopt = wopt & NmOpt("NotNULL",objQual.Value) & ";"
case "fixed"
wopt = wopt & NmOpt("Fixed",objQual.Value) & ";"
case "constructor"
wopt = wopt & NmOpt("Constructor",objQual.Value) & ";"
case "destructor"
wopt = wopt & NmOpt("Destructor",objQual.Value) & ";"
case "propagated"
wopt2 = wopt2 & "Propagated=" & objQual.Value & ";"
case "modelcorrespondence"
wopt2 = wopt2 & StrArr(objQual.Value,"ModelCorrespondence=") & ";"
case else
if VarType(objQual.Value) = (vbVariant + vbArray) then
wqlf = wqlf & " QLF:" & _
objQual.Name & "=" & Join(objQual.Value,vbCRLF & " ")
else
wqlf = wqlf & " QLF:" & _
objQual.Name & "=" & objQual.Value & vbCRLF
end If
call CollectQlf(param & "-" & objQual.Name,objQual.Value)
end select
next
if wopt2 <> "" then
wopt = wopt & vbCRLF & " " & wopt2
end if
if wopt <> "" then wopt = Replace(" /*" & wopt & "*/",";*/","*/")
if not IsNull(wval) then
'''wscript.echo "VALtn=" & TypeName(wval)
'''wscript.echo "MAPtn=" & TypeName(wmap)
'''wscript.echo "DEFtn=" & TypeName(wdef)
if IsEmpty(wmap) then 'enumerated (kind of)
' Array Constant
wscript.echo " const " & _
name & "_ENUM_" & woname & " = (""" & Join(wval,""",""") & """);"
else
' Decoding Function
wk = 0
wf = wf & "select case " & woname & vbCRLF
for each welm in wval
'''wscript.echo "ETN=" & TypeName(welm)
wf = wf & " case " & wmap(wk) & " RSLT=""" & welm & """"
'''wscript.echo "TN=" & TypeName(wmap)
if not IsEmpty(wdef) then
if wk <= Ubound(wdef) then
wf = wf & " defval=" & wdef(wk)
end if
end if
if not IsEmpty(wdscr) then
if wk <= Ubound(wdscr) then
wf = wf & " /* " & wdscr(wk) & " */"
end if
end if
wf = wf & vbCRLF
wk = wk+1
next
wf = wf & "end case '" & woname & vbCRLF
end if
end if
if wqlf <> "" then wrslt = wrslt & wqlf
if wout <> "" then wrslt = wrslt & wout
if wf <> "" then wrslt = wrslt & wf
if wopt <> "" then wrslt = wrslt & wopt
if wsmap <> "" then
wrslt = wrslt & vbCRLF & " /*" &_
Replace(wsmap & "*/",vbCRLF & "*/","*/" & vbCRLF)
end if
DumpQual = wrslt
end function
sub CollectQlf(name,val)
if InStr(strQual,vbCRLF & name & "=") = 0 then
strQual = strQual & name & "=" & Shorten(StrArr(val,""),30) & vbCRLF
end if
end sub
sub DumpProp(obj,param)
dim objProp,ws
for each objProp in obj.Properties_
'wscript.echo " /*" & param & " Property*/ " & objProp.Name & ": " &_
' objProp.Qualifiers_("CIMTYPE")
ws = DumpQual(objProp,param,obj.Path_.Class)
ws = Replace(ws,";);",");")
wscript.echo " " & objProp.Name & ": " & _
objProp.Qualifiers_("CIMTYPE") & "; " & _
CutCRLF(ws)
next
end sub
function ObjType(obj)
on error resume next
ObjType = ""
ObjType = obj.Qualifiers_("CIMTYPE")
end function
'Method-bypass_getobject
'Method-cpp_quote
'Method-HeaderName
'Method-Privileges
'Method-Schema
'Method-WmiMethodId
sub DumpMethod(obj)
dim objMethod,objInParam,wres,ws
for each objMethod in obj.Methods_
wres = " " & objMethod.Name & "("
wscript.echo DumpQual(objMethod,"Method",obj.Path_.Class)
'''wscript.echo " VT=" & VarType(objMethod.inParameters) & " TN=" & TypeName(objMethod.inParameters)
if TypeName(objMethod.inParameters) <> "Nothing" then
set objInParam = objMethod.inParameters.SpawnInstance_()
'''wscript.echo "Param TypeName=" & TypeName(objInParam)
wres = wres & DumpParams(objInParam) ' parameters
end if
ws = ObjType(obj)
if ws = "" then ' it's procedure
wres = CutCRLF(wres) & ");"
else ' it's function
wres = CutCRLF(wres) & "):" & ws & ";" ' return type
end if
set objInParam = Nothing
wscript.echo CutCRLF(wres)
next
end sub
function StrArr(val,str) ' handles both strings and string arrays
on error resume next
StrArr = "?????"
if VarType(Val) = (vbVariant + vbArray) then
StrArr = str & "[" & Join(Val,";") & "]"
else
StrArr = str & Val
end if
end function
function DumpParams(obj)
dim objProp,objQual,wtype,wdesc,wid,wres
wres = ""
for each objProp in obj.Properties_ ' individual parameters
wtype = ""
wdesc = ""
wid = ""
for each objQual in objProp.Qualifiers_
if objQual.Name = "CIMTYPE" then wtype = objQual.Value
if objQual.Name = "ID" then wid = objQual.Value
if objQual.Name = "Description" then wdesc = StrArr(objQual.Value,"")
' other ??????????????????
next
'''wscript.echo " Param: " & objProp.Name & " " & wtype & ";" & wdesc
' name:type
if wres = "" then
wres = objProp.Name & ":" & wtype
else
wres = wres & " " & objProp.Name & ":" & wtype
end if
if wdesc <> "" then
wres = wres & "; /* " & wdesc & "*/"
else
wres = wres & ";"
end if
wres = wres & vbCRLF
next
DumpParams = wres
end function
function SortArray(parr)
dim aList,wi,wx,wres
set aList = CreateObject("System.Collections.ArrayList" )
for wi = 0 to Ubound(parr)
aList.Add Trim(parr(wi))
next
aList.Sort
redim wres(Ubound(parr))
wi = 0
for each wx in aList
wres(wi) = wx
wi = wi+1
next
SortArray = wres
set aList = Nothing
end function
' Qualifier "ValueMap" corresponds to qualifier "Values" or "DefineValues" or both
' also "ValueDescriptions" may be present
' cpp_quote - looks like C++ quotation - should go to description
'make constants of then
' ID, WmiDataID? , etc. - make them comments
' DisplayName - same thing
' MappingStrings=
' follows the list of strings separated with "|"