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 for the user profile. User names are case-insensitive.
[in] Buffer of user-specific encrypted data, such as a password.
[in] Size of the user secret data.
[in] Specifies that a new user is created if the name specified in lpszUserName does not already exist on the system.
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, GetLastError returns ERROR_USER_EXISTS. If the call fails for any other reason, this function returns FALSE and logs the current user off.
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 GetLastError returns 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 lpszUserName and lpbUserSecret to NULL, dwDataSize to zero, and bCreateIfNew to FALSE.