CredRead function
Applies to: desktop apps only
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
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.
Remarks
If the value of the Type member of the CREDENTIAL structure specified by the Credential parameter is CRED_TYPE_DOMAIN_EXTENDED, a namespace must be specified in the target name. This function can return only one credential of the specified type.
Requirements
|
Minimum supported client | Windows XP |
|---|---|
|
Minimum supported server | Windows Server 2003 |
|
Header |
|
|
Library |
|
|
DLL |
|
|
Unicode and ANSI names | CredReadW (Unicode) and CredReadA (ANSI) |
Send comments about this topic to Microsoft
Build date: 3/13/2012
- CRED_TYPE_GENERIC
- 1
The credential is a generic credential. The credential will not be used by any particular authentication package. The credential will be stored securely but has no other significant characteristics.
- CRED_TYPE_DOMAIN_PASSWORD
- 2
The credential is a password credential and is specific to Microsoft's authentication packages. The NTLM, Kerberos, and Negotiate authentication packages will automatically use this credential when connecting to the named target.
- CRED_TYPE_DOMAIN_CERTIFICATE
- 3
The credential is a certificate credential and is specific to Microsoft's authentication packages. The Kerberos, Negotiate, and Schannel authentication packages automatically use this credential when connecting to the named target.
- CRED_TYPE_DOMAIN_VISIBLE_PASSWORD
- 4
This value is no longer supported.
Windows Server 2003 and Windows XP: The credential is a password credential and is specific to authentication packages from Microsoft. The Passport authentication package will automatically use this credential when connecting to the named target.
Additional values will be defined in the future. Applications should be written to allow for credential types they do not understand.
- CRED_TYPE_DOMAIN_EXTENDED
- 6
- 12/1/2009
- Jack Tripper
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);
- 7/29/2008
- ddaS-edEn