使用 vbscript 从 WMI 类获取描述

发布于 2024-09-28 11:12:43 字数 870 浏览 0 评论 0原文

如何使用 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());
}

这张图片显示了我需要的内容。

替代文本

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橙幽之幻 2024-10-05 11:12:43

下面是与 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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文