Windows CE .NET

This function sets the current user as logged on.

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


[in] NULL-terminated string containing the user's logon name. The name must be a valid file name because a directory is created that contains the user's personal data. User names are case-insensitive.
[in] Buffer of user-specific opaque secret data, such as a password.
[in] Size of the user secret data.
[in] Creates a new user if it does not already exist.

Return Values

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


SetCurrentUser is accessible only to trusted applications.

When the user is logged on, this function adjusts the registry as applicable, and provides the user secret data to the security subsystem to unlock the user's credentials. This function logs off the previous user, if present.

If the new user is the same as the previous user, the call fails and GetLastError returns ERROR_USER_EXISTS, leaving the same user logged on and makes no call to the security subsystem. In any other case, when SetCurrentUser fails, the current user is logged off and no user will be logged on.

If no there is no user, set lpszUserName and lpbUserSecret to NULL, dwDataSize to zero, and bCreateIfNew to FALSE.


OS Versions: Windows CE .NET 4.0 and later.
Header: Mwinreg.h.
Link Library: Coredll.lib.

See Also

SetUserData | GetUserNameEx | RegReplaceKey | RegSaveKey | Trusted APIs

Last updated on Wednesday, April 13, 2005

© 2005 Microsoft Corporation. All rights reserved.