2010-10-20 114 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