Directory Services

Example Code for Creating an External crossRef Object

The following Visual Basic code example shows how to create an external crossRef object.

[Visual Basic]
' CreateCrossRef()
'
' Description: Creates a crossRef object in the partitions container.
'
' Parameters:
'
' CrossRefName - Contains the name of the crossRef object.
'
' CrossRefDNSRoot - Contains the value to be set for the dNSRoot attribute of
' the crossRef object.
'
' CrossRefNCName - Contains the value to be set for the nCName attribute of
' the crossRef object.
'

Sub CreateCrossRef(CrossRefName, _
					CrossRefDNSRoot, _
					CrossRefNCName)
	Dim oRootDSE As IADs
	Dim oPartitions As IADsContainer
	Dim ADsPath As String
	Dim oCrossRef As IADs

	' Get the configurationNamingContext property from the RootDSE object.
	Set oRootDSE = GetObject("LDAP://RootDSE")
	ADsPath = "LDAP://CN=Partitions," + oRootDSE.Get("configurationNamingContext")

	' Bind to the Partitions container.
	Set oPartitions = GetObject(ADsPath)

	' Create the crossRef object.
	Set oCrossRef = oPartitions.Create("crossRef", "CN=" & CrossRefName)

	' Set the dNSRoot attribute.
	oCrossRef.Put "dNSRoot", CrossRefDNSRoot

	' Set the nCName attribute.
	oCrossRef.Put "nCName", CrossRefNCName

	' Commit the crossRef object to the directory.
	oCrossRef.SetInfo
End Sub