创建用户帐号 [英] Creating user account

查看:65
本文介绍了创建用户帐号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我创建新的用户帐户并为其设置管理员成员身份.创建了帐户,但权限设置失败,并显示错误.

Hi, all!

I create new user account and set admin membership for it. Account created, but privileges setting failed with error.

void createUser()
{
	WCHAR userName[] = L"test_user";
	NET_API_STATUS nStatus;
	USER_INFO_1 ui;
	DWORD dLevel = 1;
	DWORD dwError = 0;
	ui.usri1_name = userName;
	ui.usri1_password = L"123456123456";
	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;
	nStatus = NetUserAdd(NULL,
						 dLevel,
						 (LPBYTE)&ui,
						 &dwError);
	if (nStatus == NERR_Success)
	{
		cout << "User account created successfully" << endl;
	}
	else
	{
		cout << "User account creating failed" << endl;
	}

	GROUP_USERS_INFO_0 gi;
	gi.grui0_name = L"Administrators";
	nStatus = NetUserSetGroups(
		NULL,
		userName,
		0,
		(LPBYTE)&gi,
		1);
	if (nStatus == NERR_Success)
	{
		cout << "Adding to Administrators completed" << endl;
	}
	else
	{
		cout << "Adding to Administrators failed" << endl;
	}
}



此代码返回错误997:正在进行重叠的I/O操作.

有人知道,怎么做对吗?

谢谢.



This code return error 997: Overlapped I/O operation in progress.

Somebody know, how to do it right?

Thanks.

推荐答案

在调试器下运行它,并找出在何处抛出了异常. 看来您需要等到一项操作完成后再开始另一项操作.
你能适应吗?尝试在没有NetUserSetGroups的情况下执行NetUserAdd.它通过了吗?显示什么状态?

您的支票(nStatus == NERR_Success)错误.所有其他值如何?如果不是NERR_Success,则应该输出任何其他值,并且不要像执行操作那样无条件地继续操作.另外,对不成功的操作抛出异常.您将在堆栈顶部的某个位置捕获它们.

如果仍然无法解决问题,请获取所有其他信息并将其发布.使用改善问题".

—SA
Run it under debugger and find out where exactly exception was thrown, in what line.
It looks like you need to wait until one operation is not complete when you start another one.
Can you conform it? Try to do NetUserAdd without NetUserSetGroups. Does it passes? What status is shown?

Your check (nStatus == NERR_Success) is wrong. How about all other values? You should output any other value if it is not NERR_Success and do not continue operation unconditionally as you do. Also, throw exception out of your method on non-successful operation; you will catch them somewhere on top of the stack.

If you still cannot figure out the problem, get all the additional information and post it. Use "Improve question".

—SA


这篇关于创建用户帐号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆