P°idßnφ organizaΦnφ jednotky do domΘny

Funkce:
V deklaraΦnφ Φßsti formulß°e zapiÜte:

Private Function AddOU(ByVal OUName As String, _
Optional Description As String) As Boolean

   'PARAMETRY: OUName -- jmΘno organizaΦnφ jednotky
   'Description (Optional) -- Popis organizaΦnφ jednotky

   'POÄADAVKY: ADSI, LDAP provider. U₧ivatel
   'musφ mφt prßva pro p°idßnφ organizaΦnφ jednotky


   Dim oRoot As IADs
   Dim oContainer As IADsContainer
   Dim oOrgUnit As IADsOU

   Dim sDomain As String

   On Error GoTo ErrHandler:

   Set oRoot = GetObject("LDAP://rootDSE")

   'ZjiÜt∞nφ aktußlnφ domΘny
   sDomain = oRoot.Get("defaultNamingContext")
   Set oContainer = GetObject("LDAP://" & sDomain)

   'Vytvo°enφ novΘ OU
   Set oOrgUnit = oContainer.Create("organizationalUnit", "OU=" & OUName)
   If Trim(Description) <> "" Then oOrgUnit.Description = Description

   'Ulo₧enφ
   oOrgUnit.SetInfo
   AddOU = True

ErrHandler:
   Set oOrgUnit = Nothing
   Set oContainer = Nothing
   Set oRoot = Nothing

End Function

P°φklad volßnφ:
AddOU "IT", "Odd∞lenφ informaΦnφch technologiφ"

Zp∞t

Autor: The Bozena