Search code examples
windowsvbscriptwmi

get the description from an WMI class using vbscript


How can I get the description from an WMI class using vbscript?

I found this example but it's in C#:

// Gets the class description.
try
{
    // Gets the property qualifiers.
    ObjectGetOptions op = new ObjectGetOptions(null, System.TimeSpan.MaxValue, true);

    ManagementClass mc = new ManagementClass(namespace,
        classname, op);
    mc.Options.UseAmendedQualifiers = true;

    foreach (QualifierData dataObject in
        mc.Qualifiers)
    {
        if(dataObject.Name.Equals("Description"))
        {
            classdesc = 
                dataObject.Value.ToString();
        }
    }
}
catch (ManagementException mErr)
{
    if(mErr.Message.Equals("Not found "))
        MessageBox.Show("WMI class or not found.");
    else
        MessageBox.Show(mErr.Message.ToString());
}

This image shows what I need.

alt text


Solution

  • Here's the VBScript equivalent of your C# code (only without error handling):

    Const wbemFlagUseAmendedQualifiers = &H20000
    
    strComputer = "."
    Set oWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
    Set oClass = oWMI.Get("Win32_LogicalDisk", wbemFlagUseAmendedQualifiers)
    
    strDesc = oClass.Qualifiers_("Description").Value
    WScript.Echo strDesc