Nota:
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
En este tema se muestra cómo crear varios tipos de grupos.
Al crear un nuevo grupo, puede utilizar indicadores de la enumeración ADS_GROUP_TYPE_ENUM para asignar un tipo de grupo al grupo, por ejemplo, global (ADS_GROUP_TYPE_GLOBAL_GROUP), local de dominio (ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP), local (ADS_GROUP_TYPE_LOCAL_GROUP), universal (ADS_GROUP_TYPE_UNIVERSAL_GROUP) o con seguridad habilitada (ADS_GROUP_TYPE_SECURITY_ENABLED). Si no especifica ningún tipo de grupo, la opción predeterminada es crear un grupo protegido y global (ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP | ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED). Para obtener más información acerca de la enumeración ADS_GROUP_TYPE_ENUM, vea "ADS_GROUP_TYPE_ENUM" en la biblioteca de MSDN en https://go.microsoft.com/fwlink/?LinkID=27252.
El siguiente ejemplo de código de Visual Basic .NET muestra cómo crear un nuevo grupo, denominado Practice Managers en una unidad organizativa denominada Consulting. En un dominio, el atributo samAccountName es obligatorio, pero en Windows Server 2003 o un dominio posterior, el atributo samAccountName es opcional. Para obtener más información acerca del atributo sAMAccountName, vea el tema sobre "sAMAccountName" o el atributo "sAMAccountName" (en inglés) en la biblioteca de MSDN en https://go.microsoft.com/fwlink/?LinkID=27252.
' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()
' Find the container (in this case, the Consulting organizational unit) that you
' wish to add the new group to.
Dim ou As DirectoryEntry = dom.Children.Find("OU=Consulting")
' Add the new group Practice Managers.
Dim group As DirectoryEntry = ou.Children.Add("CN=Practice Managers", "group")
' Set the samAccountName for the new group.
group.Properties("samAccountName").Value = "pracmans"
' Commit the new group to the directory.
group.CommitChanges()
El siguiente ejemplo de código de C# muestra cómo crear un nuevo grupo, denominado Practice Managers en una unidad organizativa denominada Consulting. En un dominio, el atributo samAccountName es obligatorio, pero en Windows Server 2003 o un dominio posterior, el atributo samAccountName es opcional. Para obtener más información acerca del atributo sAMAccountName, vea el tema sobre sAMAccountName o el atributo SAM-Account-Name en la biblioteca de MSDN en https://go.microsoft.com/fwlink/?LinkID=27252.
// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();
// Find the container (in this case, the Consulting organizational unit) that you
// wish to add the new group to.
DirectoryEntry ou = dom.Children.Find("OU=Consulting");
// Add the new group Practice Managers.
DirectoryEntry group = ou.Children.Add("CN=Practice Managers", "group");
// Set the samAccountName for the new group.
group.Properties["samAccountName"].Value = "pracmans";
// Commit the new group to the directory.
group.CommitChanges();
El siguiente ejemplo de código de Visual Basic .NET muestra cómo crear un grupo de dominio local denominado Managers en la unidad organizativa Consulting. Utilice Utilizar Interoperabilidad COM para obtener acceso a ADSI para especificar el indicador ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP.
' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()
' Find the container (in this case, the Consulting organizational unit) that you
' wish to add the new local domain group to.
Dim ou As DirectoryEntry = dom.Children.Find("OU=Consulting")
' Add the Managers group.
Dim mgr As DirectoryEntry = ou.Children.Add("CN=Managers", "group")
' Set the group type to a secured domain local group.
mgr.Properties("groupType").Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP Or ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED
' Commit the new group to the directory.
mgr.CommitChanges()
El siguiente ejemplo de código de C# muestra cómo crear un grupo de dominio local denominado Managers en la unidad organizativa Consulting. Utilice Utilizar Interoperabilidad COM para obtener acceso a ADSI para especificar el indicador ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP.
// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();
// Find the container (in this case, the Consulting organizational unit) that you
// wish to add the new local domain group to.
DirectoryEntry ou = dom.Children.Find("OU=Consulting");
// Add the Managers group.
DirectoryEntry mgr = ou.Children.Add("CN=Managers", "group");
// Set the group type to a secured domain local group.
mgr.Properties["groupType"].Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_DOMAIN_LOCAL_GROUP |
ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURITY_ENABLED;
// Commit the new group to the directory.
mgr.CommitChanges();
El siguiente ejemplo de código de Visual Basic .NET muestra cómo crear un grupo no de seguridad, que es una lista de distribución denominada Full Time Employees, en la unidad organizativa Consulting. Utilice Utilizar Interoperabilidad COM para obtener acceso a ADSI para especificar el indicador ADS_GROUP_TYPE_GLOBAL_GROUP.
' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()
' Find the container (in this case, the Consulting organizational unit) that you
' wish to add the Full Time Employees distribution list to.
Dim ou As DirectoryEntry = dom.Children.Find("OU=Consulting")
' Add the Full Time Employees distribution list.
Dim dl As DirectoryEntry = ou.Children.Add("CN=Full Time Employees", "group")
' Set the group type to global.
dl.Properties("groupType").Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP
' Commit the new group to the directory.
dl.CommitChanges()
El siguiente ejemplo de código de C# muestra cómo crear un grupo no de seguridad, que es una lista de distribución denominada Full Time Employees, en la unidad organizativa Consulting. Utilice Utilizar Interoperabilidad COM para obtener acceso a ADSI para especificar el indicador ADS_GROUP_TYPE_GLOBAL_GROUP.
// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();
// Find the container (in this case, the Consulting organizational unit) that you
// wish to add the Full Time Employees distribution list to.
DirectoryEntry ou = dom.Children.Find("OU=Consulting");
// Add the Full Time Employees distribution list.
DirectoryEntry dl = ou.Children.Add("CN=Full Time Employees", "group");
// Set the group type to global.
dl.Properties["groupType"].Value = ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL_GROUP;
// Commit the new group to the directory.
dl.CommitChanges();
El siguiente ejemplo de código de Visual Basic .NET muestra cómo agregar un grupo completo a otro grupo.
' Bind to the domain that this user is currently connected to.
Dim dom As New DirectoryEntry()
' Find the container (in this case, the North America group) that you
' wish to add.
Dim group As DirectoryEntry = dom.Children.Find("CN=North America")
' Connect to the group that you wish to add "group" to.
Dim mgr As New DirectoryEntry("LDAP://CN=Managers,OU=Consulting,DC=Fabrikam,DC=COM")
' Add the distinguishedName of "group" to the members property of "mgr".
mgr.Properties("member").Add(group.Properties("distinguishedName").Value)
' Commit the changes to the directory.
mgr.CommitChanges()
El siguiente ejemplo de código de C# muestra cómo agregar un grupo completo a otro grupo.
// Bind to the domain that this user is currently connected to.
DirectoryEntry dom = new DirectoryEntry();
// Find the container (in this case, the North America group) that you
// wish to add.
DirectoryEntry group = dom.Children.Find("CN=North America");
// Connect to the group that you wish to add "group" to.
DirectoryEntry mgr = new DirectoryEntry("LDAP://CN=Managers,OU=Consulting,DC=Fabrikam,DC=COM");
// Add the distinguishedName of "group" to the members property of "mgr".
mgr.Properties["member"].Add(group.Properties["distinguishedName"].Value);
// Commit the changes to the directory.
mgr.CommitChanges();
Consulte también
Referencia
Conceptos
Administración de grupos
Utilizar Interoperabilidad COM para obtener acceso a ADSI
Send comments about this topic to Microsoft.
Copyright © 2007 Microsoft Corporation. Reservados todos los derechos.