网站首页  词典首页

请输入您要查询的函数:

 

术语 netuseradd
释义 NetUserAdd
语法:
C++
NET_API_STATUS NetUserAdd(
__in LMSTR servername,
__in DWORD level,
__in LPBYTE buf,
__out LPDWORD parm_err
);
NetUserAdd功能
该NetUserAdd函数将一个用户帐户和密码,并分配一个权限级别。
参数
服务器名 [in]
指针常量字符串指定的DNS或NetBIOS的远程服务器上的功能是执行的名称。如果该参数为NULL,则使用本地计算机。
这个字符串是Unicode或FORCE_UNICODE如果_WIN32_WINNT定义。
Level [in]
指定的数据信息的Level。此参数可以是下列值之一。
ValueMeaning
1Specifies信息的用户帐户。在buf参数指向一个USER_INFO_1结构。
当您指定此级别,呼叫某些属性初始化为默认值。有关详细信息,请参阅下面的备注部分。
2SpecifiesLevel1的信息和用户帐户的其他属性。在buf参数指向一个USER_INFO_2结构。
3Specifies第二级信息和用户帐户的其他属性。这个级别只适用于服务器。在buf参数指向一个USER_INFO_3结构。请注意,建议您使用USER_INFO_4代替。
4Specifies第二级信息和用户帐户的其他属性。这个级别只适用于服务器。在buf参数指向一个USER_INFO_4结构。
Windows 2000中:此级别不支持。
缓冲带 [in]
缓冲区指针指定的数据。这一数据格式取决于Level的参数值。有关更多信息,请参阅网络管理功能的缓冲器。
parm_err [out]
指针的值,它接收了用户信息的结构的第一个成员的索引导致ERROR_INVALID_PARAMETER。如果该参数为NULL,则指数不返回的错误。有关详细信息,请参阅NetUserSetInfo功能。
返回值
如果函数成功,返回值是NERR_Success。
如果函数失败,返回值可以是下面的错误代码之一。
返回codeDescription
ERROR_ACCESS_DENIEDThe用户没有获得所需的信息。
NERR_InvalidComputerThe计算机名无效。
NERR_NotPrimaryThe操作只允许在该域的主域控制器。
NERR_GroupExistsThe组已经存在。
NERR_UserExistsThe用户帐户已经存在。
NERR_PasswordTooShortThe密码少于需要。 (密码也可以太长,太在其历史上最近的变化,没有足够的独特的字符,或一个新的密码不符合政策的要求。)
备注
如果您是Active Directory的程序,您可以调用某些Active Directory服务接口(ADSI)的方法来达到同样的功能,您可以通过调用用户的网络管理功能。有关更多信息,请参阅IADsUser和IADsComputer。
如果您调用域控制器上运行Active Directory的这一功能,允许访问或拒绝的访问控制列表的安全对象(ACL)的基础。默认的ACL只允许域管理员和Account Operators调用此函数。在成员服务器或工作站,只有Administrators和Power Users可以调用这个函数。有关更多信息,请参阅的网络管理功能的安全要求。欲了解更多有关的ACL,ACE的,和访问令牌信息,请访问控制模型。
用户的容器的安全描述符用于执行此函数访问检查。调用者必须能够创造出用户类子对象。
服务器用户必须使用制度,服务器会创建新用户的制度。该帐户的建立,是控制在服务器的LanMan.ini文件中的几个参数。
如果新添加的用户已经作为一个系统的用户,该USER_INFO_1结构usri1_home_dir成员存在被忽略。
当您调用NetUserAdd函数并指定信息化Level1,调用初始化在USER_INFO_2,USER_INFO_3和USER_INFO_4结构的成员,以它们的默认值。您可以通过制定后续调用NetUserSetInfo函数的默认值。提供的默认值列出如下。 (前缀usriX表明,成员国可以开始与多个前缀,例如,usri2_或usri4_。)
MemberDefault价值
usriX_auth_flagsNone(0)
usriX_full_nameNone(空字符串)
usriX_usr_commentNone(空字符串)
usriX_parmsNone(空字符串)
usriX_workstationsAll(空字符串)
usriX_acct_expiresNever(TIMEQ_FOREVER)
usriX_max_storageUnlimited(USER_MAXSTORAGE_UNLIMITED)
usriX_logon_hoursLogon可以在任何时间(每个元素0xFF;所有位设置为1)
usriX_logon_serverAny域控制器(\\ \\ *)
usriX_country_code0
usriX_code_page0
用户帐户名称被限制为20个字符和组名称被限制为256个字符。此外,帐户名称不能终止的期间,他们不能包含逗号或以下打印字符:“,/,\\,[,]:,|,”,“+,=,,,?, *.名称也不能包括在1-31范围内,这些非打印字符。
实例
下面的代码示例演示如何添加一个用户帐户和权限级别分配使用调用NetUserAdd功能。此代码示例填充在USER_INFO_1结构的成员,并呼吁NetUserAdd,明确信息化Level1。
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include
#include
#include
int wmain(int argc, wchar_t *argv[])
{
USER_INFO_1 ui;
DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus;
if (argc != 3)
{
fwprintf(stderr, L"Usage: %s \\\\\\\\ServerName UserName\\n", argv[0]);
exit(1);
}
//
// Set up the USER_INFO_1 structure.
// USER_PRIV_USER: name identifies a user,
// rather than an administrator or a guest.
// UF_SCRIPT: required
//
ui.usri1_name = argv[2];
ui.usri1_password = argv[2];
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;
//
// Call the NetUserAdd function, specifying level 1.
//
nStatus = NetUserAdd(argv[1],
dwLevel,
(LPBYTE)&ui,
&dwError);
//
// If the call succeeds, inform the user.
//
if (nStatus == NERR_Success)
fwprintf(stderr, L"User %s has been successfully added on %s\\n",
argv[2], argv[1]);
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\\n", nStatus);
return 0;
}
要求:
最低支持:client-Windows 2000专业版
最低支持server-Windows 2000服务器
HeaderLmaccess.h(包括Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
参见
网络管理概述
网络管理功能
用户功能
NetUserEnum
NetUserSetInfo
NetUserDel
USER_INFO_1
USER_INFO_2
USER_INFO_4
如果有任何问题和意见,请发送给微软(wsddocfb@microsoft.com)
生成日期:2009年8月13日
==英文原文==NetUserAdd Function
The NetUserAdd function adds a user account and assigns a password and privilege level.
Syntax
C++
NET_API_STATUS NetUserAdd(
__in LMSTR servername,
__in DWORD level,
__in LPBYTE buf,
__out LPDWORD parm_err
);
Parameters
servername [in]
Pointer to a constant string that specifies the DNS or NetBIOS name of the remote server on which the function is to execute. If this parameter is NULL, the local computer is used.
This string is Unicode if _WIN32_WINNT or FORCE_UNICODE are defined.
level [in]
Specifies the information level of the data. This parameter can be one of the following values.
ValueMeaning
1Specifies information about the user account. The buf parameter points to a USER_INFO_1 structure.
When you specify this level, the call initializes certain attributes to their default values. For more information, see the following Remarks section.
2Specifies level one information and additional attributes about the user account. The buf parameter points to a USER_INFO_2 structure.
3Specifies level two information and additional attributes about the user account. This level is valid only on servers. The buf parameter points to a USER_INFO_3 structure. Note that it is recommended that you use USER_INFO_4 instead.
4Specifies level two information and additional attributes about the user account. This level is valid only on servers. The buf parameter points to a USER_INFO_4 structure.
Windows 2000: This level is not supported.

buf [in]
Pointer to the buffer that specifies the data. The format of this data depends on the value of the level parameter. For more information, see Network Management Function Buffers .
parm_err [out]
Pointer to a value that receives the index of the first member of the user information structure that causes ERROR_INVALID_PARAMETER. If this parameter is NULL, the index is not returned on error. For more information, see the NetUserSetInfo function.
Return Value
If the function succeeds, the return value is NERR_Success.
If the function fails, the return value can be one of the following error codes.
Return codeDescription
ERROR_ACCESS_DENIEDThe user does not have access to the requested information.
NERR_InvalidComputerThe computer name is invalid.
NERR_NotPrimaryThe operation is allowed only on the primary domain controller of the domain.
NERR_GroupExistsThe group already exists.
NERR_UserExistsThe user account already exists.
NERR_PasswordTooShortThe password is shorter than required. (The password could also be too long, be too recent in its change history, not have enough unique characters, or not meet another password policy requirement.)

Remarks
If you are programming for Active Directory, you may be able to call certain Active Directory Service Interface (ADSI) methods to achieve the same functionality you can achieve by calling the network management user functions. For more information, see IADsUser and IADsComputer .
If you call this function on a domain controller that is running Active Directory, access is allowed or denied based on the access control list (ACL) for the securable object . The default ACL permits only Domain Admins and Account Operators to call this function. On a member server or workstation, only Administrators and Power Users can call this function. For more information, see Security Requirements for the Network Management Functions . For more information on ACLs, ACEs, and access tokens, see Access Control Model .
The security descriptor of the user container is used to perform the access check for this function. The caller must be able to create child objects of the user class.
Server users must use a system in which the server creates a system account for the new user. The creation of this account is controlled by several parameters in the server's LanMan.ini file.
If the newly added user already exists as a system user, the usri1_home_dir member of the USER_INFO_1 structure is ignored.
When you call the NetUserAdd function and specify information level 1, the call initializes the additional members in the USER_INFO_2 , USER_INFO_3 , and USER_INFO_4 structures to their default values. You can change the default values by making subsequent calls to the NetUserSetInfo function. The default values supplied are listed following. (The prefix usriX indicates that the member can begin with multiple prefixes, for example, usri2_ or usri4_.)
MemberDefault Value
usriX_auth_flagsNone (0)
usriX_full_nameNone (null string)
usriX_usr_commentNone (null string)
usriX_parmsNone (null string)
usriX_workstationsAll (null string)
usriX_acct_expiresNever (TIMEQ_FOREVER)
usriX_max_storageUnlimited (USER_MAXSTORAGE_UNLIMITED)
usriX_logon_hoursLogon allowed at any time (each element 0xFF; all bits set to 1)
usriX_logon_serverAny domain controller (\\\\*)
usriX_country_code0
usriX_code_page0

User account names are limited to 20 characters and group names are limited to 256 characters. In addition, account names cannot be terminated by a period and they cannot include commas or any of the following printable characters: ", /, \\, [, ], :, |, <, >, +, =, ;, ?, *. Names also cannot include characters in the range 1-31, which are nonprintable.
Examples
The following code sample demonstrates how to add a user account and assign a privilege level using a call to the NetUserAdd function. The code sample fills in the members of the USER_INFO_1 structure and calls NetUserAdd, specifying information level 1.
#ifndef UNICODE
#define UNICODE
#endif
#pragma comment(lib, "netapi32.lib")
#include
#include
#include
int wmain(int argc, wchar_t *argv[])
{
USER_INFO_1 ui;
DWORD dwLevel = 1;
DWORD dwError = 0;
NET_API_STATUS nStatus;
if (argc != 3)
{
fwprintf(stderr, L"Usage: %s \\\\\\\\ServerName UserName\\n", argv[0]);
exit(1);
}
//
// Set up the USER_INFO_1 structure.
// USER_PRIV_USER: name identifies a user,
// rather than an administrator or a guest.
// UF_SCRIPT: required
//
ui.usri1_name = argv[2];
ui.usri1_password = argv[2];
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;
//
// Call the NetUserAdd function, specifying level 1.
//
nStatus = NetUserAdd(argv[1],
dwLevel,
(LPBYTE)&ui,
&dwError);
//
// If the call succeeds, inform the user.
//
if (nStatus == NERR_Success)
fwprintf(stderr, L"User %s has been successfully added on %s\\n",
argv[2], argv[1]);
//
// Otherwise, print the system error.
//
else
fprintf(stderr, "A system error has occurred: %d\\n", nStatus);
return 0;
}
Requirements
Minimum supported clientWindows 2000 Professional
Minimum supported serverWindows 2000 Server
HeaderLmaccess.h (include Lm.h)
LibraryNetapi32.lib
DLLNetapi32.dll
See Also
Network Management Overview
Network Management Functions
User Functions
NetUserEnum
NetUserSetInfo
NetUserDel
USER_INFO_1
USER_INFO_2
USER_INFO_4
Send comments about this topic to Microsoft
Build date: 8/13/2009
==原始网址==http://msdn.microsoft.com/en-us/library/aa370649(VS.85).aspx\n
随便看

 

windows api函数参考手册包含2258条windows api函数文档,详细介绍nodejs、java、rust调用windows api的方法技巧,是学习windows api编程的入门中文文档。

 

Copyright © 2004-2023 Winrtm.com All Rights Reserved
京ICP备2021023879号-40 更新时间:2024/10/6 13:24:47