How to Use NetUserAdd

Last reviewed: October 21, 1996
Article ID: Q140165
The information in this article applies to:
  • Microsoft Win32 Software Development Kit (SDK) versions 3.1, 3.5, 3.51, 4.0

SUMMARY

NetUserAdd allows a Windows NT application to add a user to a Windows NT workstation or server programmatically. Adding a user with this function seems easy enough, but there are a few issues that are not obvious.

MORE INFORMATION

If you would like to add users to a Windows NT workstation or server in your application, you must use NetUserAdd. Given a server name, level, and appropriate structure, a new user will be created. The following pointers may help you avoid problems:

  1. As required of all Net* functions, submit all strings in UNICODE (wide characters). Use MultiByteToWideChar to convert standard ASCII strings into UNICODE strings. Don't forget to include the terminating NULL in string conversions.

  2. Specify the server name as \\server. Be sure to include double backslashes, four backslashes if inside a C literal string.

  3. Use the UF_SCRIPT required flag. Without it, you will get ERROR_INVALID_PARAMETER.

  4. When using level 2, make sure your strings do not exceed the maximum lengths. Constants are defined for the maximum lengths. For example, the maximum lengths for params, comment, user comment, and full name is MAXCOMMENTSZ. Paths must fit within PATHLEN characters. UNC names for servers must fit in UNCLEN characters.

  5. Use NetUserAdd only to add user accounts, not guest or administrator accounts. After the account is established, use NetUserSetGroups to add Administrator, Guest, or other groups to the new user account.

REFERENCES

Microsoft LAN Manager, A Programmer's Guide by Ralph Ryan. Microsoft LAN Manager Programmer's Reference. Win32 SDK Documentation.


Additional reference words: NETUSERADD LANMAN 3.10 3.50 3.51 4.00
KBCategory: kbnetwork kbprg kbhowto
KBSubcategory: NtwkMisc


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: October 21, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.