在 Windows 7 操作系统上创建/删除新用户帐户
我想在我的代码上创建和删除新用户。我设法使用“NetUser”类的“createUser()”函数进行创建,但是当我按照参考中的方式设置选项来创建标准用户时,它仍然创建为来宾帐户。有谁知道我的问题的原因是什么?
我正在使用此代码:
//userinfo structure:
ui.usri1_name = username;
ui.usri1_password = password;
ui.usri1_priv = USER_PRIV_USER;
ui.usri1_home_dir = NULL;
ui.usri1_comment = NULL;
ui.usri1_flags = UF_SCRIPT;
ui.usri1_script_path = NULL;
//Creating user:
DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus;
nStatus = NetUserAdd(L"localhost",dwLevel,(LPBYTE)&ui,&dwError);
这应该创建一个新的用户帐户作为标准用户帐户,但它始终创建一个任务用户帐户。该函数在凭据提供程序中运行,因此我认为问题不在于权限。有关 NetUserAdd 函数的详细信息 单击。
I want to create and delete new users on my code. I managed to create with "NetUser" class's "createUser()" functions but when I set the options as in the references to create a standard user, it still creating as a guest account. Is there anyone knows what is the reason of my problem?
I am using this code:
//userinfo structure:
ui.usri1_name = username;
ui.usri1_password = password;
ui.usri1_priv = USER_PRIV_USER;
ui.usri1_home_dir = NULL;
ui.usri1_comment = NULL;
ui.usri1_flags = UF_SCRIPT;
ui.usri1_script_path = NULL;
//Creating user:
DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus;
nStatus = NetUserAdd(L"localhost",dwLevel,(LPBYTE)&ui,&dwError);
This should create a new user account to be a standard user account but it is always creating a quest user account. This function is running in a credential provider hence I don't think the problem is about the permissions. For more information about the NetUserAdd function click.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须将用户添加到名为“Users”的本地组中。因此,您可以使用 NetLocalGroupAddMembers< /a> 函数。
本地组 Users 的名称取决于安装的 Windows 版本的语言。为了获取本地组“Users”的名称,您可以使用 CreateWellKnownSid(WinBuiltinUsersSid 为 WellKnownSidType)和 LookupAccountSid。
You have to add the user to the local group called "Users". Therefore you can use the NetLocalGroupAddMembers function.
The name of the local group Users depends on the language of the installed Windows version. In order to get the name of the local group "Users" you can use CreateWellKnownSid (with WinBuiltinUsersSid as WellKnownSidType) and LookupAccountSid.
这是我在 Windows 中创建帐户的示例。如果您想将此帐户添加到本地用户以便您可以登录当前计算机,则需要调用 NetLocalGroupAddMembers 函数。作为本地组名称,您应该只键入“Users”,但它会因 Windows 的语言版本而异。在波兰语版本中,它将是“Użytkownicy”等。
如果您想在远程服务器上添加帐户,则需要调用 NetGetDCName 并提供第一个参数给它服务器地址。然后在本例的其他函数中使用PDC。
请记住以管理员身份运行此代码(即使是 IDE,如果处于调试状态),否则您将出现访问被拒绝的错误。
Here is my example creating an account in Windows. If You want to add this account to local users so You could log on current machine it is necessary to call NetLocalGroupAddMembers function. As a local group name You should type just "Users", but it varies on the language version of Windows. On polish version it would be "Użytkownicy" and etc.
If You want to add an account on a remote server then it needed to call NetGetDCName and ass first parameter give it server address. Then use PDC in other functions in this example.
REMEMBER to run this code as Administrator(even IDE if in debug) or You will have access denied error.