在 Configuration Manager 中,通过调用 SWbemServices 对象 ExecQueryAsync 方法并实现接收器方法来处理查询结果,对 Configuration Manager 对象执行同步查询。
若要处理每个返回的对象,请创建 objWbemSink.OnObjectReady 事件子例程。 若要在查询完成时收到通知,请创建 objWbemSink.OnCompleted 事件子例程。
注意
异步查询中不返回延迟属性。 有关详细信息,请参阅 如何使用 WMI 读取延迟属性。
执行异步查询
设置与 SMS 提供程序的连接。 有关详细信息,请参阅如何使用 WMI 连接到 Configuration Manager 中的 SMS 提供程序。
创建 OnObjectReady 子例程以通过查询处理对象。
创建 OnCompleted 子例程来处理查询完成。
使用从步骤 1 获取的 SWbemServices 对象,使用 ExecQueryAsync 对象异步查询Configuration Manager对象。
示例
以下 VBScript 代码示例异步查询所有 SMS_Collection 对象。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
Dim bdone
Sub QueryCollection(connection)
Dim sink
bdone = False
Set sink = WScript.CreateObject("wbemscripting.swbemsink","sink_")
' Query for all collections.
connection.ExecQueryAsync sink, "select * from SMS_Collection"
' Wait until all instances are returned.
While Not bdone
wscript.sleep 1000
Wend
End Sub
' The sink subroutine to handle the OnObjectReady
' event. This is called as each object returns.
Sub sink_OnObjectReady(collection, octx)
WScript.Echo "CollectionID: " + collection.CollectionID
WScript.Echo "Name: " + collection.Name
Wscript.Echo
End Sub
' The sink subroutine to handle the OnCompleted event.
' This is called when all the objects are returned.
' The oErr parameter obtains an SWbemLastError object,
' if available from the provider.
Sub sink_OnCompleted(HResult, oErr, oCtx)
WScript.Echo "All collections returned"
bdone = true
End Sub
此示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
connection |
SWbemServices | 与 SMS 提供程序的有效连接。 |
另请参阅
Windows Management Instrumentation对象概述如何使用 WMI 调用Configuration Manager对象类方法如何使用 WMI 在 Configuration Manager中连接到 SMS 提供程序如何使用 WMI 创建Configuration Manager对象 如何通过 WMI 创建Configuration Manager对象如何使用 WMI 删除Configuration Manager对象如何使用 WMI 修改Configuration Manager对象如何使用 WMI 执行同步Configuration Manager查询如何读取Configuration Manager使用 WMI对象 如何使用 WMI 读取延迟属性Configuration Manager扩展 WMI 查询语言Configuration Manager结果集Configuration Manager有关查询的特殊查询