'Add a reference to ActiveDS Type library.
'Search for TODO in the following code to set configuration
'information.
'
Private Type SERVICE_STATUS
dwServiceType As Long
dwCurrentState As Long
dwControlsAccepted As Long
dwWin32ExitCode As Long
dwServiceSpecificExitCode As Long
dwCheckPoint As Long
dwWaitHint As Long
End Type
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SC_MANAGER_CONNECT = &H1
Private Const SC_MANAGER_CREATE_SERVICE = &H2
Private Const SC_MANAGER_ENUMERATE_SERVICE = &H4
Private Const SC_MANAGER_LOCK = &H8
Private Const SC_MANAGER_MODIFY_BOOT_CONFIG = &H20
Private Const SC_MANAGER_QUERY_LOCK_STATUS = &H10
Private Const SC_MANAGER_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or _
SC_MANAGER_CONNECT Or SC_MANAGER_CREATE_SERVICE Or _
SC_MANAGER_ENUMERATE_SERVICE Or SC_MANAGER_LOCK Or _
SC_MANAGER_QUERY_LOCK_STATUS Or SC_MANAGER_MODIFY_BOOT_CONFIG)
Private Const SERVICE_USER_DEFINED_CONTROL = &H100
Private Declare Function CloseServiceHandle Lib _
"advapi32.dll" (ByVal hSCObject As Long) As Long
Private Declare Function OpenSCManager Lib _
"advapi32.dll" Alias "OpenSCManagerA" (ByVal lpMachineName As String, ByVal lpDatabaseName As _
String, ByVal dwDesiredAccess As Long) As Long
Private Declare Function OpenService Lib "advapi32.dll" Alias "OpenServiceA" (ByVal hSCManager As Long, ByVal lpServiceName As String, ByVal dwDesiredAccess As Long) As Long
Private Declare Function ControlService Lib "advapi32.dll" _
(ByVal hService As Long, ByVal dwControl As Long, lpServiceStatus As SERVICE_STATUS) As Long
Private Sub Main()
Dim objExistingCont As IADsContainer
Dim objNewCont As IADs
Dim sstStatus As SERVICE_STATUS
Dim hSCM As Long
Dim hService As Long
' Bind to an existing container.
//TODO : Change the ADsPath to reflect your Exchange Organization.
Set objExistingCont = GetObject("LDAP://MyExchServer/ou=MySite,o=MyOrg")
' Make a new container<BR/>
//TODO: Set the new container directory name.
Set objNewCont = objExistingCont.Create("Container","cn=MyNewCont")
' Put the continer-info prop to tell Exchange this is a recipients cont.
objNewCont.Put "Container-Info", &H80000001
//TODO: Change the next line to set the Display name.
objNewCont.Put "Admin-Display-Name", "MyNewCont"
objNewCont.SetInfo
Set objCont = Nothing
Set objNewCR = Nothing<BR/>
'Now recalculate the address book hierarchy.
//TODO: change first paramater to the name of the Exchange server.
hSCM = OpenSCManager("\\MyExchServer", vbNullString, SC_MANAGER_ALL_ACCESS)
hService = OpenService(hSCM, "MSExchangeDS", SERVICE_USER_DEFINED_CONTROL)
lret = ControlService(hService, 129, sstStatus)
lret = CloseServiceHandle(hService)
lret = CloseServiceHandle(hSCM)
End Sub