|
|
The following program checks whether the specified DC is a GC server and if it is so instructed, changes the status of the DC.
Listing 17.16. SetGC.bas — Designating a DC as a Global Catalog Server
Option Explicit Sub Main() Dim strDSSettings, strServerDN As String Dim objRootDSE As IADs Dim objDsService As IADs Dim objComp As IADs Dim iFlag As Integer ' Bind to the RootDSE on a specific server Set objRootDSE = GetObject("LDAP://netdc2.subdom.net.dom/RootDSE") '*** Get the Directory Service Settings *** strDSSettings = objRootDSE. Get ("dsServiceName") Debug.Print "NTDS Settings: " + strDSSettings Set objDsService = Getobject ("LDAP: //" & strDSSettings) ' *** Get the distinguished name of the server *** strServerDN = objRootDSE. Get ("serverName") Debug. Print "Server Name: " + strServerDN Set objComp = GetObject ("LDAP: //" & strServerDN) On Error Resume Next iFlag = objDsService.Get ("options") If Hex (Err.Number) = "8000500D" Then Debug.Print "PROPERTY_NOT_FOUND" iFlag = 0 End If Debug.Print "Current flag value is " + CStr (iFlag) ' Remove comment marks (') from necessary statements to toggle the status ' of the server If (iFlag And 1) Then Debug.Print objComp.Get("name") + " IS a GC server" ' Revoke the GC server role: ' objDsService.Put "options", iFlag Xor 1 'clear the flag ' objDsService.SetInfo ' Debug.Print objComp.Get ("name") + " is no longer a GC server" Else Debug.Print objComp.Get ("name") + " is NOT a GC server" ' Assign the GC server role: ' Debug.Print objComp.Get ("name") + _ "will be advertised as a GC server" ' objDsService.Put "options", iFlag Xor 1 'set the flag ' objDsService.SetInfo End If Set objRootDSE = Nothing Set objDsService = Nothing Set objComp = Nothing End Sub
|
|