WinBioRemoveCredential 函式 (winbio.h)

刪除指定使用者生物特徵辨識登入認證。 從 Windows 10 組建 1607 開始,此函式可用來搭配行動映射使用。

語法

HRESULT WinBioRemoveCredential(
  [in] WINBIO_IDENTITY        Identity,
  [in] WINBIO_CREDENTIAL_TYPE Type
);

參數

[in] Identity

包含將移除登入認證的用戶帳戶 SID 的WINBIO_IDENTITY 結構。

[in] Type

指定認證類型的 WINBIO_CREDENTIAL_TYPE 值。 這個值可以是下列其中一個值:

意義
WINBIO_CREDENTIAL_PASSWORD
密碼型認證將會被刪除。
WINBIO_CREDENTIAL_ALL
將會刪除使用者的所有登入認證。

傳回值

如果函式成功,它會傳回S_OK。 如果函式失敗,它會傳回 HRESULT 值,指出錯誤。 可能的值包括 (但不限於) 下表中的這些值。 如需常見錯誤碼的清單,請參閱 一般 HRESULT 值

傳回碼 Description
E_ACCESSDENIED
呼叫端沒有刪除認證的許可權。
WINBIO_E_CRED_PROV_NO_CREDENTIAL
指定的身分識別不存在或沒有認證存放區中的任何相關記錄。

備註

沒有提高許可權的使用者只能刪除自己的認證。 提高許可權的使用者可以移除任何用戶帳戶的認證。 刪除認證不會影響該使用者的任何生物特徵辨識註冊。 刪除生物特徵辨識認證並不會防止使用者使用密碼登入。 只有中型和更高的完整性程式可以刪除認證。 如果較低的完整性進程嘗試刪除認證,函式會傳回E_ACCESSDENIED。

範例

下列函式示範如何呼叫 WinBioRemoveCredential 來移除特定用戶的認證。 也包含協助程式函式 GetCurrentUserIdentity。 連結到Winbio.lib 靜態庫,並包含下列頭檔:

  • Windows.h
  • Stdio.h
  • Conio.h
  • Winbio.h
HRESULT RemoveCredential()
{
    HRESULT hr = S_OK;
    WINBIO_IDENTITY identity;

    // Find the identity of the user.
    wprintf_s(L"\n Finding user identity.\n");
    hr = GetCurrentUserIdentity( &identity );
    if (FAILED(hr))
    {
        wprintf(L"\n User identity not found. hr = 0x%x\n", hr);
        goto e_Exit;
    }

    // Remove the user credentials.
    hr = WinBioRemoveCredential(identity, WINBIO_CREDENTIAL_PASSWORD);
    if (FAILED(hr)) 
    {
        wprintf(L"\n WinBioRemoveCredential failed. hr = 0x%x\n", hr);
        goto e_Exit;
    }

    wprintf_s(L"\n User credentials successfully removed.\n");

e_Exit:

    wprintf_s(L"\n Press any key to exit...");
    _getch();

    return hr;
}

//------------------------------------------------------------------------
// The following function retrieves the identity of the current user.
// This is a helper function and is not part of the Windows Biometric
// Framework API.
//
HRESULT GetCurrentUserIdentity(__inout PWINBIO_IDENTITY Identity)
{
    // Declare variables.
    HRESULT hr = S_OK;
    HANDLE tokenHandle = NULL;
    DWORD bytesReturned = 0;
    struct{
        TOKEN_USER tokenUser;
        BYTE buffer[SECURITY_MAX_SID_SIZE];
    } tokenInfoBuffer;

    // Zero the input identity and specify the type.
    ZeroMemory( Identity, sizeof(WINBIO_IDENTITY));
    Identity->Type = WINBIO_ID_TYPE_NULL;

    // Open the access token associated with the
    // current process
    if (!OpenProcessToken(
            GetCurrentProcess(),            // Process handle
            TOKEN_READ,                     // Read access only
            &tokenHandle))                  // Access token handle
    {
        DWORD win32Status = GetLastError();
        wprintf_s(L"Cannot open token handle: %d\n", win32Status);
        hr = HRESULT_FROM_WIN32(win32Status);
        goto e_Exit;
    }

    // Zero the tokenInfoBuffer structure.
    ZeroMemory(&tokenInfoBuffer, sizeof(tokenInfoBuffer));

    // Retrieve information about the access token. In this case,
    // retrieve a SID.
    if (!GetTokenInformation(
            tokenHandle,                    // Access token handle
            TokenUser,                      // User for the token
            &tokenInfoBuffer.tokenUser,     // Buffer to fill
            sizeof(tokenInfoBuffer),        // Size of the buffer
            &bytesReturned))                // Size needed
    {
        DWORD win32Status = GetLastError();
        wprintf_s(L"Cannot query token information: %d\n", win32Status);
        hr = HRESULT_FROM_WIN32(win32Status);
        goto e_Exit;
    }

    // Copy the SID from the tokenInfoBuffer structure to the
    // WINBIO_IDENTITY structure. 
    CopySid(
        SECURITY_MAX_SID_SIZE,
        Identity->Value.AccountSid.Data,
        tokenInfoBuffer.tokenUser.User.Sid
        );

    // Specify the size of the SID and assign WINBIO_ID_TYPE_SID
    // to the type member of the WINBIO_IDENTITY structure.
    Identity->Value.AccountSid.Size = GetLengthSid(tokenInfoBuffer.tokenUser.User.Sid);
    Identity->Type = WINBIO_ID_TYPE_SID;

e_Exit:

    if (tokenHandle != NULL)
    {
        CloseHandle(tokenHandle);
    }

    return hr;
}


規格需求

需求
最低支援的用戶端 Windows 7 [僅限傳統型應用程式]
最低支援的伺服器 Windows Server 2008 R2 [僅限傳統型應用程式]
目標平台 Windows
標頭 winbio.h (包含Winbio.h)
程式庫 Winbio.lib
Dll Winbio.dll

另請參閱

WinBioRemoveAllCredentials

WinBioRemoveAllDomainCredentials

WinBioSetCredential