Hi People, when I try to modify an active directory user programatically , I
receive the following exception:
The server is unwilling to process the request
Reading the microsoft web site, I found this article:
http://support.microsoft.com/default...b;EN-US;248717 that says the
following:
............... ...........
To Make Modifications Using ADSI Scripts
Active Directory Services Interfaces (ADSI) can make modifications to the
schema through its Lightweight Directory Access Protocol (LDAP) provider.
The code below determines the location of the schema, bind to the attribute
in the schema, and make the necessary changes to force it to replicate to
the GC.
Const ADS_PROPERTY_CL EAR = 1
' Declarations are commented for use with VBScript
Dim oRootDSE 'As IADs
Dim oConn 'As ADODB.Connectio n
Dim oRecordset 'As ADODB.Recordset
Dim strAttribute 'As String
Dim strADsPath 'As String
Dim oAttribute 'As IADs
Dim bReplicate 'As Boolean
strAttribute = "Department " 'Replace with the name of the attribute to
change replication
bReplicate = True 'Replicate to GC True/False
Set oConn = CreateObject("A DODB.Connection ")
Set oRootDSE = GetObject("LDAP ://RootDSE")
oConn.Provider = "ADsDSOObje ct"
oConn.Open "ADs Provider"
strQuery = "<LDAP://" & oRootDSE.Get("s chemaNamingCont ext")
& ">;(&(objectCla ss=attributeSch ema)(cn=" & strAttribute &
"));cn,adspath; subtree"
Set oRecordset = oConn.Execute(s trQuery)
oRecordset.Move First
strADsPath = oRecordset.Fiel ds("ADsPath") 'store the path of the object in
the schema
Set oAttribute = GetObject(strAD sPath) 'Get the object in the schema
If bReplicate Then
oAttribute.Put "isMemberOfPart ialAttributeSet ", True 'Set the property
to true
Else
oAttribute.PutE x ADS_PROPERTY_CL EAR, "isMemberOfPart ialAttributeSet ", 0
'Clear the property
End If
'Write to schema
oAttribute.SetI nfo
'Clean Up
Set oAttribute = Nothing
Set oRootDSE = Nothing
oRecordset.Clos e
oConn.Close
Set oConn = Nothing
Set oRecordset = Nothing
If the above registry change is not made, the following error occurs
when attempting to run the script:
Error -2147016651 (80072035): Automation error. The server is unwilling to
process the request.
............... ..........
My code is the following:
public DataSet modifyUser(Cont enedorUsuario v_objContenedor Usuario) {
string strFullName = v_objContenedor Usuario.obtener Nombre() +" "+
v_objContenedor Usuario.obtener PrimerApellido( ) +" "+
v_objContenedor Usuario.obtener SegundoApellido ();
DirectoryEntry objNewUser = null;
try
{
/* get the current user */
objNewUser = getDirectoryEnt ry(v_objContene dorUsuario.getU niqueId());
}
catch(Exception e)
{
throw new Exception("Usua rio no Existe y no se puede modificar");
}
if (objNuevoUsuari o == null)
{
throw new Exception("Usua rio no Existe y no se puede modificar");
}
try
{
#region invoke Properties
/* si no se setea esta propiedad, provoca una exception de: The server is
unwilling to process the request,
* para mas detalles ver:
http://support.microsoft.com/default...b;EN-US;248717 */
Boolean objBoolean = true;
objNuevoUsuario .Properties["isMemberOfPart ialAttributeSet "].Value =
objBoolean;
/* seccion de atributos obligatorios de Active Directory */
invocarPropieda d(ref objNuevoUsuario ,"name",strNomb reCompleto);
invocarPropieda d(ref
objNuevoUsuario ,"givenName",v_ objContenedorUs uario.obtenerNo mbre());
invocarPropieda d(ref
objNuevoUsuario ,"Description", v_objContenedor Usuario.obtener Descripcion());
invocarPropieda d(ref
objNuevoUsuario ,"samAccountNam e",v_objContene dorUsuario.obte nerLogin());
/* Seccion de atributos extendidos de Active Directory */
/* Para detalles ver:
http://www.microsoft.com/latam/techn...ws2k/chapt-20/ */
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute1",v_objCo ntenedorUsuario .obtenerCedula( )
);
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute2",v_objCo ntenedorUsuario .obtenerCorreoE l
ectronico());
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute3",v_objCo ntenedorUsuario .obtenerDeparta m
ento());
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute4",v_objCo ntenedorUsuario .obtenerEntidad (
));
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute5",v_objCo ntenedorUsuario .obtenerJefeDir e
cto());
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute6",v_objCo ntenedorUsuario .obtenerNombre( )
);
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute7",v_objCo ntenedorUsuario .obtenerPrimerA p
ellido());
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute8",v_objCo ntenedorUsuario .obtenerPuesto( )
);
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute9",v_objCo ntenedorUsuario .obtenerSegundo A
pellido());
invocarPropieda d(ref
objNuevoUsuario ,"extensionAttr ibute10",v_objC ontenedorUsuari o.obtenerTelefo n
o());
/* solamente modifica el password si esta definido */
if(v_objContene dorUsuario.obte nerClave() != "" &&
v_objContenedor Usuario.obtener Clave() != null)
{
objNuevoUsuario .Invoke("SetPas sword", new object[]
{v_objContenedo rUsuario.obtene rClave() });
}
#endregion
/* Hace "Commit" de los cambios, para asegurar que se realicen en el Active
Directory */
objNuevoUsuario .CommitChanges( );
/* se retorna el objeto correspondiente al nuevo usuario */
return convertirUsuari oADataSet(objNu evoUsuario);
}
catch(Exception e)
{
throw e;
}
}
I'm using a user with full rights to modify the active directory. Any idea
why the The server is unwilling to process the request exception???