2010-10-20 156 views
1

如何从使用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

给,你希望看到什么类的一个实例。 – ghostdog74 2010-10-20 14:31:25

回答

3

下面是等价的VBScript的C#代码(仅适用于没有错误处理):

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 
+0

+1 @ Helen。你击败了我。 – Garett 2010-10-20 18:38:40

+0

非常感谢海伦。 – Salvador 2010-10-21 00:50:01