CredUICredUICmdLinePromptForCredentials Method

prompts for and accepts credential information from a user working in a command-line (console) application.

The name and password typed by the user are passed back to the calling application for verification.

Definition

Namespace: DevCase.Win32.NativeMethods
Assembly: DevCase.net48 (in DevCase.net48.dll) Version: 6.0.0.0 (6.0)
XMLNS for XAML: Not mapped to an xmlns.
[DllImportAttribute("CredUI.dll", CharSet = CharSet.Auto, BestFitMapping = false, 
	ThrowOnUnmappableChar = true, SetLastError = true)]
public static Win32ErrorCode CredUICmdLinePromptForCredentials(
	[OptionalAttribute] string targetName,
	[OptionalAttribute] IntPtr reserved,
	Win32ErrorCode authError,
	StringBuilder userName,
	uint userNameSize,
	StringBuilder password,
	uint passwordSize,
	ref bool refSave,
	CredentialsDialogOptions flags
)

Parameters

targetName  String  (Optional)
A pointer to a null-terminated string that contains the name of the target for the credentials,

typically a server name. For DFS connections, this string is of the form ServerName/ShareName.

The targetName parameter is used to identify the target information and is used to store and retrieve the credential.

reserved  IntPtr  (Optional)
Currently reserved and must be Zero.
authError  Win32ErrorCode
Specifies why prompting for credentials is needed.

A caller can pass this Windows error parameter, returned by another authentication call, to allow the dialog box to accommodate certain errors.

For example, if the password expired status code is passed, the dialog box prompts the user to change the password on the account.

userName  StringBuilder
A pointer to a null-terminated string that contains the credential user name.

If a nonzero-length string is specified for userName, the user will be prompted only for the password.

In the case of credentials other than username/password, a marshaled format of the credential can be passed in. This string is created by calling CredMarshalCredential function.

This function writes the user-supplied name to this buffer, copying a maximum of userNameSize characters. The string in this format can be converted to the user name/password format by calling the CredUIParseUserName(String, StringBuilder, Int32, StringBuilder, Int32) function. The string in its marshaled format can be passed directly to a security support provider (SSP).

If the DoNotPersist flag is not specified, the value returned in this parameter is of a form that should not be inspected, printed, or persisted other than passing it to CredUIParseUsername.

The subsequent results of CredUIParseUserName(String, StringBuilder, Int32, StringBuilder, Int32) can be passed only to a client-side authentication API such as WNetAddConnection or the SSP API.

userNameSize  UInt32
The maximum number of characters that can be copied to userName including the terminating null character.
password  StringBuilder
A pointer to a null-terminated string that contains the password for the credentials.

If a nonzero-length string is specified for password, the password parameter will be prefilled with the string.

This function writes the user-supplied password to this buffer, copying a maximum of passwordSize characters.

If the DoNotPersist flag is not specified, the value returned in this parameter is of a form that should not be inspected, printed, or persisted other than passing it to a client-side authentication function such as WNetAddConnection or an SSP function.

When you have finished using the password, clear the password from memory by calling the SecureZeroMemory function.

passwordSize  UInt32
The maximum number of characters that can be copied to password including the terminating null character.
refSave  Boolean
A value that specifies the initial state of the Save message and receives the state of the Save message after the user has responded to the command prompt.

If refSave is not NULL and CredUIPromptForCredentials(CredUiInfo, String, IntPtr, Win32ErrorCode, StringBuilder, Int32, StringBuilder, Int32, Boolean, CredentialsDialogOptions) returns ERROR_SUCCESS, refSave returns the state of the Save message.

If the Persist flag is specified, the Save message is not displayed but is considered to be "y" (Yes).

If the DoNotPersist flag is specified and ShowSaveCheckBox is not specified, the Save message is not displayed but is considered to be "n" (No).

flags  CredentialsDialogOptions
A value that specifies special behavior for this function.

Return Value

Win32ErrorCode
Returns ERROR_SUCCESS on success, or a Win32ErrorCode error code on failure.

Remarks

See Also