Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NetUserAdd() successful, but user is "invisible"

I'm creating a user with the NetUserAdd API. It returns successfully, the user has a User folder and I can see the username with wmic useraccount get name. However, the created user is not visible under the control panel, nor on the logon screen. I assume that I need to add the user to some group but I don't know which or how.

Here is how I create the user:

USER_INFO_1 user_info;
ZeroMemory(&user_info, sizeof(user_info));
user_info.usri1_name = userName;
user_info.usri1_password = password;
user_info.usri1_priv = USER_PRIV_USER;
user_info.usri1_flags = UF_SCRIPT | UF_DONT_EXPIRE_PASSWD;

DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus = NetUserAdd(NULL, dwLevel, (LPBYTE)&user_info, &dwError);

How can I make the user visible on the logon screen?

like image 381
Tamás Szelei Avatar asked Mar 09 '12 14:03

Tamás Szelei


2 Answers

You have created the user but you need to add it to the users group using NetLocalGroupAddMembers.

EDIT: Just realized I was providing the method for .NET. See this example for C++.

like image 51
Chibueze Opata Avatar answered Nov 19 '22 02:11

Chibueze Opata


The user was not showing up on the welcome screen because it was not added to the Users group. This is how to do it:

LOCALGROUP_MEMBERS_INFO_3 lmi3;
ZeroMemory(&lmi3, sizeof lmi3);
lmi3.lgrmi3_domainandname = user_info.usri1_name;
DWORD err = NetLocalGroupAddMembers(NULL, L"Users", 3, (LPBYTE) &lmi3, 1);
like image 2
Tamás Szelei Avatar answered Nov 19 '22 00:11

Tamás Szelei