VBScript 支持对象内省吗?
我正在通过 VBScript 使用 WQL 从 WMI 拉回结果。
在示例中,For Each
循环用于迭代结果,但在每个示例中,假设属性名称已知。恰当的例子:
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer Where Default = True")
For Each objPrinter in colInstalledPrinters
Wscript.Echo objPrinter.Name
Next
某些 WMI 类具有很长的与其关联的属性列表。另一个复杂因素是,某些属性不能期望出现(根据我读过的有关 WMI 的各种网页)。我不想研究每个 WMI 类并希望列出的属性都存在,而是希望获取 objPrinter 或任何其他返回项的属性(或列,如果我在 SQL/WQL 中思考的话)存在的列表。
Python 是我常用的语言,但在本例中我无法将其安装在目标计算机上;我可以通过 Python 执行 WMI 远程查询,但我试图触发本地事件,因此又回到了 VBScript。虽然我认为 Powershell 可能能够做到这一点,但我不想现在就学习它。
那么,VBScript 是否支持允许我枚举属性列表的内省级别?或者我可以做一些涉及我可以在脚本中引用和检查的模式的事情吗?
I am pulling results back from WMI using WQL via VBScript.
In examples, a For Each
loop is used to iterate over the results, but in each example, it is assumed that the property names are known. Case in point:
Set colInstalledPrinters = objWMIService.ExecQuery ("Select * from Win32_Printer Where Default = True")
For Each objPrinter in colInstalledPrinters
Wscript.Echo objPrinter.Name
Next
Some of the WMI classes have a very long list of properties associated with them. As an additional complication, some properties cannot be expected to be present (according to various webpages I have read about WMI). Rather than researching each WMI class and hoping that the properties listed are present, I would like to obtain a list of the properties (or columns, if I am thinking in SQL/WQL) present for, say, an objPrinter or any other returned item.
Python is my usual language but I cannot install it on the target machines in this instance; I can perform remote querying of WMI via Python but I am trying to trigger on an local event, hence falling back to VBScript. Although I gather Powershell might be able to do this, I would rather not learn it just this instant.
So, does VBScript support that level of introspection which would allow me to enumerate a list of properties? Or is there something I can do involving a schema I can reference and examine in-script?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用该项目的 .Properties_ 集合:
输出:
显然,ToString() 函数需要进一步工作。
Use the .Properties_ collection of the item:
Output:
Obviously, the ToString() function needs further work.