Delen via


Accountvergrendeling (WinNT-provider)

Wanneer het aantal mislukte aanmeldingspogingen wordt overschreden, wordt het gebruikersaccount vergrendeld voor het aantal minuten dat is opgegeven door het kenmerk lockoutDuration. De eigenschap IADsUser.IsAccountLocked lijkt de eigenschap te zijn die moet worden gebruikt om de vergrendelingsstatus van een gebruikersaccount te lezen en te wijzigen, maar de WinNT ADSI-provider heeft beperkingen die het gebruik van de eigenschap IsAccountLocked beperken.

De vergrendelingsstatus van het account opnieuw instellen

Wanneer u de WinNT-provider gebruikt, kan de eigenschap IsAccountLocked alleen worden ingesteld op FALSE-, waarmee het account wordt ontgrendeld. Het instellen van de eigenschap IsAccountLocked op TRUE- mislukt. Alleen het systeem kan een account vergrendelen.

In het volgende codevoorbeeld ziet u hoe u Visual Basic met ADSI gebruikt om een gebruikersaccount te ontgrendelen.

Public Sub UnlockAccount(AccountDN As String)
    Dim usr As IADsUser
    
    ' Bind to the user account.
    Set usr = GetObject("WinNT://" + AccountDN)
    
    ' Set the IsAccountLocked property to False
    usr.IsAccountLocked = False
    
    ' Flush the cached attributes to the server.
    usr.SetInfo
End Sub

In het volgende codevoorbeeld ziet u hoe u C++ gebruikt met ADSI om een gebruikersaccount te ontgrendelen.

HRESULT UnlockAccount(LPCWSTR pwszUserDN)
{
    if(!pwszUserDN)
    {
        return E_INVALIDARG;
    }

    // Build the ADsPath.
    CComBSTR sbstr = "WinNT://";
    sbstr += pwszUserDN;
    
    HRESULT hr;
    CComPtr<IADsUser> spADsUser;

    // Bind to the object.
    hr = ADsOpenObject(sbstr,
        NULL,
        NULL,
        ADS_SECURE_AUTHENTICATION,
        IID_IADsUser,
        (void**)&spADsUser);
    if(S_OK != hr)
    {
        return hr;
    }
    
    // Set the IsAccountLocked property to FALSE;
    hr = spADsUser->put_IsAccountLocked(VARIANT_FALSE);

    // Commit the changes to the server.
    hr = spADsUser->SetInfo();

    return hr;
}

De vergrendelingsstatus van het account lezen

Met de WinNT-provider kan de eigenschap IsAccountLocked worden gebruikt om te bepalen of een account is vergrendeld. Als een account is vergrendeld, bevat de eigenschap IsAccountLockedTRUE. Als een account niet is vergrendeld, bevat de eigenschap IsAccountLockedFALSE.

In het volgende codevoorbeeld ziet u hoe u Visual Basic gebruikt met ADSI om te bepalen of een account is vergrendeld.

Public Function IsAccountLocked(AccountDN As String) As Boolean
    Dim oUser As IADsUser
    
    ' Bind to the object.
    Set oUser = GetObject("WinNT://" + AccountDN)
    
    ' Get the IsAccountLocked property.
    IsAccountLocked = oUser.IsAccountLocked
End Function

In het volgende codevoorbeeld ziet u hoe u C++ gebruikt met ADSI om te bepalen of een account is vergrendeld.

HRESULT IsAccountLocked(LPCWSTR pwszUserDN, BOOL *pfLocked)
{
    if(!pwszUserDN || !pfLocked)
    {
        return E_INVALIDARG;
    }

    *pfLocked = FALSE;

    // Build the ADsPath.
    CComBSTR sbstr = "WinNT://";
    sbstr += pwszUserDN;
    
    HRESULT hr;
    CComPtr<IADsUser> spADsUser;

    // Bind to the object.
    hr = ADsOpenObject(sbstr,
        NULL,
        NULL,
        ADS_SECURE_AUTHENTICATION,
        IID_IADsUser,
        (void**)&spADsUser);
    if(S_OK != hr)
    {
        return hr;
    }
    
    VARIANT_BOOL vfLocked;
    hr = spADsUser>get_IsAccountLocked(&vfLocked);
    if(S_OK != hr)
    {
        return hr;
    }

    *pfLocked = (vfLocked != 0);

    return hr;
}