使用vbscript从WMI类中获取描述

时间:2010-10-20 14:28:32

标签: windows vbscript wmi

如何使用vbscript从WMI类获取描述?

我找到了这个例子,但它在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());
}

此图片显示了我的需求。

alt text

1 个答案:

答案 0 :(得分:3)

这是你的C#代码的VBScript等价物(只是没有错误处理):

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