我如何获取 WMI 类方法的参数类型

发布于 2024-09-28 17:03:11 字数 460 浏览 3 评论 0原文

我如何使用 vbscript 获取 WMI 类方法的参数类型

实际上我正在使用这个脚本

strComputer = "."
strNameSpace = "root\cimv2"
Set objServices = GetObject("winmgmts:root\cimv2")
Set objShare = objServices.Get("Win32_Share")

Set objInParam = objShare.Methods_("Create"). _
    inParameters.Properties_

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo Property.Type //here this code fails, how i can get the type name ?
Next

How i can get the parameters types of an method for a WMI class using vbscript

actually i'm using this script

strComputer = "."
strNameSpace = "root\cimv2"
Set objServices = GetObject("winmgmts:root\cimv2")
Set objShare = objServices.Get("Win32_Share")

Set objInParam = objShare.Methods_("Create"). _
    inParameters.Properties_

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo Property.Type //here this code fails, how i can get the type name ?
Next

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

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

发布评论

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

评论(1

情定在深秋 2024-10-05 17:03:11

您得到的 objInParam 是 SWbemPropertySet 包含 SWbemProperty 正如您在文档中看到的,该类没有 Type 属性。但是,有 CIMType 属性您可以使用它来代替。

唯一的困难是 CIMType 返回一个 Integer,但您可以在 WbemCimTypeEnum 枚举。

因此,如果您对整数感到满意,则必须将代码更改为:

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo Property.CIMType 
Next

或者,如果您需要字符串名称,则必须执行以下操作:

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo GetTypeName(Property.CIMType)
Next

Function GetTypeName(typeNumber)
   ' fill in with a lookup table to the WbemCimTypeEnum '
End Function

The objInParam you get out is a SWbemPropertySet that contains SWbemProperty and as you can see in the docs, there is no Type property of that class. However, there is the CIMType property that you can use instead.

The only difficulty with this is that CIMType returns an Integer, but you can find all the possible values in the documentation for the WbemCimTypeEnum enum.

So if you'd be happy with the integer you'd have to change your code to:

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo Property.CIMType 
Next

Or if you need a string name you'd have to do something like:

For Each Property In objInParam 
    WScript.Echo Property.Name
    WScript.Echo GetTypeName(Property.CIMType)
Next

Function GetTypeName(typeNumber)
   ' fill in with a lookup table to the WbemCimTypeEnum '
End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文