Before connecting to the SMS Provider for a local or remote Configuration Manager 2007 site server, you first need to locate the SMS Provider for the site server. The SMS Provider can be either local or remote to the Configuration Manager site server you are using. The Windows Management Instrumentation (WMI) class SMS_ProviderLocation is present on all Configuration Manager site servers, and one instance will contain the location for the Configuration Manager site server you are using.

You can connect to the SMS Provider on a Configuration Manager site server by using the WMI object or by using the Windows Script Host GetObject method. Both approaches work equally well on local or remote connections, with the following limitations:

There are several different syntaxes that you can use to make the connection, depending on whether the connection is local or remote. After you are connected to the SMS Provider, you will have an object that you use to access Configuration Manager 2007 objects.

If you need to add context qualifiers for the connection, see How to Add a Configuration Manager Context Qualifier by Using WMI.

To connect to an SMS provider

  1. Get a WbemScripting.SWbemLocator object.

  2. Set the authentication level to packet privacy.

  3. Set up a connection to the SMS Provider by using the SWbemLocator object ConnectServer method. Supply credentials only if it is a remote computer.

  4. Using the SMS_ProviderLocation object ProviderForLocalSite property, connect to the SMS Provider for the local computer and receive a SWbemServicesObject.

  5. Use the SWbemServices object to access provider objects. For more information, see About Configuration Manager Objects.


The following VB Script example connects to the server. It then attempts to connect to the SMS Provider for that server. Typically this will be the same computer. If it is not, SMS_ProviderLocation provides the correct computer name.

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

Visual Basic Script  Copy Code
Function Connect(server, userName, userPassword)

	On Error Resume Next

	Dim net
	Dim localConnection
	Dim swbemLocator
	Dim swbemServices
	Dim providerLoc
	Dim location

	Set swbemLocator = CreateObject("WbemScripting.SWbemLocator")

	swbemLocator.Security_.AuthenticationLevel = 6 'Packet Privacy.

	' If the server is local, don't supply credentials.
	Set net = CreateObject("WScript.NetWork") 
	If UCase(net.ComputerName) = UCase(server) Then
		localConnection = true
		userName = ""
		userPassword = ""
		server = "."
	End If

	' Connect to the server.
	Set swbemServices= swbemLocator.ConnectServer _
			(server, "root\sms",userName,userPassword)
	If Err.Number<>0 Then
		Wscript.Echo "Couldn't connect: " + Err.Description
		Connect = null
		Exit Function
	End If

	' Determine where the provider is and connect.
	Set providerLoc = swbemServices.InstancesOf("SMS_ProviderLocation")

		For Each location In providerLoc
			If location.ProviderForLocalSite = True Then
				Set swbemServices = swbemLocator.ConnectServer _
				 (location.Machine, "root\sms\site_" + _
				If Err.Number<>0 Then
					Wscript.Echo "Couldn't connect:" + Err.Description
					Connect = Null
					Exit Function
				End If
				Set Connect = swbemServices
				Exit Function
			End If
	Set Connect = null ' Failed to connect.
End Function

Compiling the Code

This C# example requires:


The sample method has the following parameters:

Parameter Type Description


  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.


  • Managed: IResultObject

  • VBScript: SWbemObject

A valid task sequence (SMS_TaskSequence).


  • Managed: String

  • VBScript: String

A valid task sequence XML.

Robust Programming

For more information about error handling, see About Configuration Manager Errors.


Using script to pass the user name and password is a security risk and should be avoided where possible.

The preceding example sets the authentication to packet privacy. This is the same managed SMS Provider.

For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also

Send comments about this topic to Microsoft.