tags:

views:

12

answers:

1

How i can get the parameters types of an method for a WMI class using vbscript

actually i'm using this script

strComputer = "."
strNameSpace = "root\cimv2"
Set objServices = GetObject("winmgmts:root\cimv2")
Set objShare = objServices.Get("Win32_Share")

Set objInParam = objShare.Methods_("Create"). _
    inParameters.Properties_

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo Property.Type //here this code fails, how i can get the type name ?
Next
+2  A: 

The objInParam you get out is a SWbemPropertySet that contains SWbemProperty and as you can see in the docs, there is no Type property of that class. However, there is the CIMType property that you can use instead.

The only difficulty with this is that CIMType returns an Integer, but you can find all the possible values in the documentation for the WbemCimTypeEnum enum.

So if you'd be happy with the integer you'd have to change your code to:

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo Property.CIMType 
Next

Or if you need a string name you'd have to do something like:

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo GetTypeName(Property.CIMType)
Next

Function GetTypeName(typeNumber)
   ' fill in with a lookup table to the WbemCimTypeEnum '
End Function
ho1
+1 thanks very much.
Salvador