Hello everybody,
im trying hard to automate some tasks in a huge windows environment.
This lend me to bigger problems while trying to create new global
security groups within active directory. First I tried to add the groups
as discribed in article "Creating Groups" at Platform SDK:
System.DirectoryServices documentation. I figuerd out that something in
the article was missing, because groupcreation ended in an error: "A
constraint violation occured." The missing thing was to set the property
for "sAMAccountName". Now a new error occures wich bothers me: "A device
attached to the system is not functioning."
Anyone encountered similar problems or - even better- anyone solved this
problem?
Here a small codesnipplet for problemtracing...
----- snip ----------------------------------------------------------
public int createOuTree( ArrayList toAdd )
{
int returnValue = 0;
DirectoryEntries adsRoot = pubAds.Children;
DirectoryEntry newOu;
DirectoryEntry newSubOu;
DirectoryEntry genGrp;
foreach ( string addOu in toAdd )
{
try
{
newOu = adsRoot.Add("OU=" + addOu, "organizationalUnit");
newOu.CommitChanges();
}
catch( COMException e )
{
returnValue = 1;
exception = e.Message.ToString();
continue;
}
DirectoryEntries genChildOus = newOu.Children;
foreach ( string subOu in schemaDef )
{
try
{
newSubOu = genChildOus.Add( "OU=" + subOu, "organizationalUnit" );
newSubOu.CommitChanges();
Console.WriteLine( "\t|- {0} (subou)", subOu );
if ( subOu == schemaGroupentriesPrefixes[0] )
{
int i = 1;
while ( i < schemaGroupentriesPrefixes.Length )
{
string groupID = "CN=" + schemaGroupentriesPrefixes[i] +
addOu.ToString();
Console.WriteLine( "\t|\t|- {0} (securitygroup)",
schemaGroupentriesPrefixes[i] + addOu );
try
{
genGrp = newSubOu.Children.Add( groupID, "group" );
genGrp.Properties["groupType"].Value =
ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_GLOBAL _GROUP |
ActiveDs.ADS_GROUP_TYPE_ENUM.ADS_GROUP_TYPE_SECURI TY_ENABLED;
genGrp.Properties["sAMAccountName"].Value = groupID;
genGrp.Properties["description"].Value = "Standard Group for OU "
+ addOu.ToString();
genGrp.CommitChanges();
i++;
}
catch ( Exception e )
{
Console.WriteLine( "Caught exception: \"{0}\", while adding group
{1}", e.Message, groupID );
i++;
continue;
}
}
}
}
catch( COMException e)
{
returnValue = 1;
exception = e.Message.ToString();
continue;
}
}
}
genGrp = null;
newSubOu = null;
newOu = null;
adsRoot = null;
return returnValue;
}
---- snap ------------------------------------------------------
Best regards
Sergej Pioch