To call a SMS Provider class method, in Configuration Manager 2007, you use the SWbemServices object ExecMethod method to call methods that are defined by the class.

Note
To call a method on an object instance, call the method from the object directly. For example, ObjectInstance.MethodName parameters.

To call a Configuration Manager object class method

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Using the SWbemServices you obtain in step one, call Get to get the class definition.

  3. Create the input parameters as a SWbemMethodSet.

  4. Using the SWbemServices object instance, call ExecuteMethod and specify the class name and input parameters.

  5. Retrieve the method return value from the ReturnValue property in the returned SWbemObject object.

Example

The following example validates a collection rule query by calling the SMS_CollectionRuleQuery class ValidateQuery class method.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Visual Basic Script  Copy Code
Sub ValidateQueryRule(connection, wqlQuery)
 
	Dim inParams
	Dim outParams
	Dim collectionRuleClass

	On Error Resume Next

	' Obtain the class definition object of a SMS_CollectionRuleQuery object.
	Set collectionRuleClass = connection.Get("SMS_CollectionRuleQuery")

	If Err.Number<>0 Then
		Wscript.Echo "Couldn't get collection rule query object"
		Exit Sub
	End If

	' Set up the in parameter.
	Set inParams = collectionRuleClass.Methods_("ValidateQuery").InParameters.SpawnInstance_
	inParams.WQLQuery = wqlQuery
	If Err.Number<>0 Then
		Wscript.Echo "Couldn't get in parameters object"
		Exit Sub
	End If

	' Call the method.
	Set outParams = _
		connection.ExecMethod( "SMS_CollectionRuleQuery", "ValidateQuery", inParams)
	If Err.Number<>0 Then
		Wscript.Echo "Couldn't run method"
		Exit Sub
	End If

	If outParams.ReturnValue = True Then
		Wscript.Echo "Valid query"
	Else 
		WScript.Echo "Not a valid query"
	End If	
  End Sub

This example method has the following parameters:

Parameter Type Description

connection

  • Managed: SWbemServices

A valid connection to the SMS Provider.

wqlQuery

  • String

A WQL query string. For this example, SELECT * FROM SMS_R_System is a valid query.

Compiling the Code

See Also


Send comments about this topic to Microsoft.