如何使用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());
}
此图片显示了我的需求。
答案 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