Programmatically assign user role
We also solved this task with the user_multiple_role_edit() function.
In our usecase we didn't react on the register-form but on a special menu-callback to create users on the fly.

First: Create a user

$user = new stdClass();
$user-&gt;name = $name;
$user-&gt;status = 1;
user_save($user);


Second: Assign the user to the role

$role = user_role_load_by_name("my custom role");
user_multiple_role_edit(array($user-&gt;uid), 'add_role', $role-&gt;rid);