Create User with entity_metadata_wrapper() in Drupal 7

Here's a little snippet to use when creating a new user with entity_metadata_wrapper():

// Get an empty object with the is_new attribute set to TRUE.
$user = entity_create('user', array());

// Define specific role IDs for the user.
$roles = array(3, 4, ...);

$user->name = 'username';
// Enable the user by default.
$user->status    = 1;
// Set nescessary role to let the user log in.
$user->roles     = drupal_map_assoc($roles + array(DRUPAL_AUTHENTICATED_RID));
// Set e-mail for lost password procedure.
$user->init      = '';
$user->mail      = '';
// Set hashed password.
$user->pass      = user_hash_password('password');

// Once we have enough data, set the wrapper around the user object.
$user = entity_metadata_wrapper('user', $user);

 * Do your things.
 // Save the user.

With that, you have enough data to start using entity_metadata_wrapper(). Don't forget to check the doc on for more info about setting fields value and so on.

Oh, and if you want the ID of the newly created user :
$uid = $user->getIdentifier();