Click to Rate and Give Feedback
MSDN
MSDN Library
Security
Authentication
 CredRead Function

  Switch on low bandwidth view
CredRead Function

The CredRead function reads a credential from the user's credential set. The credential set used is the one associated with the logon session of the current token. The token must not have the user's SID disabled.

Syntax

C++
BOOL CredRead(
  __in   LPCTSTR TargetName,
  __in   DWORD Type,
  __in   DWORD Flags,
  __out  PCREDENTIAL *Credential
);

Parameters

TargetName [in]

Pointer to a null-terminated string that contains the name of the credential to read.

Type [in]

Type of the credential to read. Type must be one of the CRED_TYPE_* defined types.

Flags [in]

Currently reserved and must be zero.

Credential [out]

Pointer to a single allocated block buffer to return the credential. Any pointers contained within the buffer are pointers to locations within this single allocated block. The single returned buffer must be freed by calling CredFree.

Return Value

The function returns TRUE on success and FALSE on failure. The GetLastError function can be called to get a more specific status code. The following status codes can be returned:

  • ERROR_NOT_FOUND

    No credential exists with the specified TargetName.

  • ERROR_NO_SUCH_LOGON_SESSION

    The logon session does not exist or there is no credential set associated with this logon session. Network logon sessions do not have an associated credential set.

  • ERROR_INVALID_FLAGS

    A flag that is not valid was specified for the Flags parameter.

Requirements

Minimum supported clientWindows XP
Minimum supported serverWindows Server 2003
HeaderWinCred.h
LibraryAdvapi32.lib
DLLAdvapi32.dll
Unicode and ANSI namesCredReadW (Unicode) and CredReadA (ANSI)

Send comments about this topic to Microsoft

Build date: 6/26/2009

Community Content   What is Community Content?
Add new content RSS  Annotations
Check if credential was saved the last time      ddaS-edEn   |   Edit   |   Show History
If you need to check if credentials were saved the last time this fragment can be used:

BOOL bExists = FALSE;

PCREDENTIAL credential;


bool exists = 0 != ::CredRead(szUrl, CRED_TYPE_GENERIC, 0, &credential);


if (exists) {
... // Saved credential exists
...
::SecureZeroMemory(credential->CredentialBlob, credential->CredentialBlobSize);
}
else {
... // No saved credential exists
...
}


::CredFree(credential);

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker