ADSI userAccountControl Furtif_00 Project
Hi everybody
I continue the last year project of Furtif_00 that you can see here :
http://www.codeguru.com/forum/showth...=309450&page=4
and i have to modify the "change password" option of a user.
i know that this could be done with the "userAccountControl" .
I try the folowing code in c++ but it doesn't work.
is somebody know how to do this??
thanks for helping me .
here is the code :
bool CActiveDirectory::expire(CCFXRequest *pRequest)
{
USES_CONVERSION;
IADsUser *pUser;
strinExpire = pRequest->GetAttribute( "Expire" );
hr = bindToUser( &pUser, pRequest );
if( SUCCEEDED( hr ))
{
if( pUser )
{
VARIANT var;
//VariantInit(&var);
//V_BSTR(&var) =A2W(strinExpire);
//V_VT(&var)=VT_BSTR;
hr=pUser->Get(L"userAccountControl",&var);
var.intVal = var.intVal^64;
if(FAILED(hr))
{
return false;
}
pUser->Put(L"userAccountControl",var);
pUser->SetInfo();
pUser->Release();
VariantClear(&var);
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
Re: ADSI userAccountControl Furtif_00 Project
Are you trying to expire the password, force the user to change it.
If so, try ( MSDN sample )
Code:
//=======================================================
// Set the pwdLastSet property to zero, which forces the
// user to change the password the next time they log on
//=======================================================
CComVariant svar;
sbstrProp = "pwdLastSet";
svar = 0;
hr = pUser->Put(sbstrProp, svar);
hr = pUser->SetInfo();
or if you are trying to set the password so it does not expire. (also from MSDN)
Code:
//==========================================================
// Add ADS_UF_DONT_EXPIRE_PASSWD flag to the
// userAccountControl property.
//==========================================================
CComVariant svar;
sbstrProp = "userAccountControl";
hr = pUser->Get(sbstrProp, &svar);
if(SUCCEEDED(hr))
{
svar = svar.lVal & (ADS_UF_DONT_EXPIRE_PASSWD);
hr = pUser->Put(sbstrProp, svar);
hr = pUser->SetInfo();
}
hr = pUser->SetInfo();
HTH
Re: ADSI userAccountControl Furtif_00 Project
I tryed out your code but the setinfo function repliy with the 0x80072035 that mean that the server cannot perform the request operation.
I will search futher and repost if i have probleme thank a lot.
Re: ADSI userAccountControl Furtif_00 Project
So now it works : the Never expire option can be set with this code :
IADsUser *pUser;
VARIANT var;
VariantInit(&var);
HRESULT hr = S_OK;
hr = pUser->Get(L"userAccountControl", &var);
if(FAILED(hr))
{
return false;
}
V_I4(&var) |= ADS_UF_DONT_EXPIRE_PASSWD;
hr = pUser->Put(L"userAccountControl", var);
if(FAILED(hr))
{
return false;
}
hr = pUser->SetInfo();
if(FAILED(hr))
{
return false;
}
VariantClear(&var);
pUser->Release();
return true;
ps : sorry i do not know how to put the code in a little windows !! ;-)
Re: ADSI userAccountControl Furtif_00 Project
I try to reset the password never expire option with the same code but
i do like this
V_I4(&var) &= !(ADS_UF_DONT_EXPIRE_PASSWD);
but it does not work
how can i do to reset this option ??
Re: ADSI userAccountControl Furtif_00 Project
Bon ba si sa marche pas demande a Dom il va te dire comment faire car lui un jour au stage d'été il sé prit une flute ds le cul ou demande a Gwenec de te preter une de ses chemises Fashion sa pourra t inspirer :)
Aller Homme des Cavernes a poils longs a plus. MSN ne marche plus car ils ont un routeur NetGear et sa fout la merde sur le réseau
Re: ADSI userAccountControl Furtif_00 Project
If you are trying to remove the flag try using the ~ operator
Code:
V_I4(&var) & ~ ( ADS_UF_ACCOUNTDISABLE );
HTH
Re: ADSI userAccountControl Furtif_00 Project
it doesn't make error just a warning : "operator & without effect, operator with secondary effect" and it does not reset the flag
i don't know the ~ operator what is it suppose to do??
Re: ADSI userAccountControl Furtif_00 Project
Had a typo sorry - try this instead......
Code:
V_I4(&var) &= ~ADS_UF_PASSWD_CANT_CHANGE;
HTH
Re: ADSI userAccountControl Furtif_00 Project
thanks a lot it's work fine