Important:
This is retired content. This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies. This content may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.
A version of this page is also available for
4/8/2010

This function sets the current user as logged on.

Syntax

BOOL SetCurrentUser( 
  LPCWSTR 
lpszUserName, 
  LPBYTE 
lpbUserSecret, 
  DWORD 
dwDataSize, 
  BOOL 
bCreateIfNew 
);

Parameters

lpszUserName

[in] NULL-terminated string containing the user's logon name. The name must be a valid file name because a directory is created for the user profile. User names are case-insensitive.

lpbUserSecret

[in] Buffer of user-specific encrypted data, such as a password.

dwDataSize

[in] Size of the user secret data.

bCreateIfNew

[in] Specifies that a new user is created if the name specified in lpszUserNamedoes not already exist on the system.

Return Value

Returns TRUE if the new user was logged on. If the specified user was already logged on, returns FALSE and leaves that user logged on. In this case, GetLastErrorreturns ERROR_USER_EXISTS. If the call fails for any other reason, this function returns FALSE and logs the current user off.

Remarks

This function is accessible only to privileged applications.

When the user is logged on, this function adjusts the registry as applicable and provides the user encrypted data to the security subsystem to unlock the user credentials. This function logs off any previous user.

If the new user is the same as the previous user, the call fails, and GetLastErrorreturns ERROR_USER_EXISTS, leaving the same user logged on. It makes no call to the security subsystem. In any other case when this function fails, the current user is logged off, and no new user is logged on.

If there is no user, set lpszUserNameand lpbUserSecretto NULL, dwDataSizeto zero, and bCreateIfNewto FALSE.

Requirements

Header pwinreg.h
Library coredll.lib
Windows Embedded CE Windows CE .NET 4.0 and later
Windows Mobile Windows Mobile Version 5.0 and later

See Also