Each query in SMS has an instance of an SMS_Query class in the SMS Provider. This example retrieves all instances of SMS_Query for the local site in a collection and then enumerates through the collection to display the names of the queries.
Example
On Error Resume Next Dim objSWbemServices Dim ProviderLoc Dim Location Dim colQueries Dim colQueryResults Dim objQuery Set ProviderLoc = GetObject("winmgmts:{impersonationLevel=impersonate}!root/sms:SMS_ProviderLocation") If err.number<>0 Then wscript.echo "Couldn't get SMS Provider" wscript.quit End If For Each Location In ProviderLoc.Instances_ If Location.ProviderForLocalSite = True Then Set objSWbemServices = GetObject("winmgmts:" & Location.NamespacePath) Exit For End If Next 'Get Status Messages. Set colQueries=objSWbemServices.InstancesOf("SMS_Query") If err.number<>0 Then wscript.echo "Couldn't get Queries" wscript.quit End If wscript.echo "QueryID QueryName" wscript.echo "-----------------" For Each objQuery In colQueries wscript.echo objQuery.Name Set colQueryResults=objSWbemServices.ExecQuery(objQuery.Expression) For Each objResult In colQueryResults wscript.echo " " + objResult.Name Next If colQueryResults.Count=0 Then wscript.echo " no query results" End If Next |
Compiling the Code
- Requires Windows 2000 Server SP2 or later.
- You must run this sample on an SMS 2003 site server.