Directory Services |
The following steps describe how to create a local user account on a computer:
Be aware that with the WinNT provider, you must set the password before calling SetInfo. Otherwise, the account creation will fail if the account does not satisfy local password policy requirements. This differs from the creation of domain user accounts using the LDAP provider, in which you must call SetInfo before you can set the password, and the account is disabled if it does not meet password policy requirements. For more information about creating domain user accounts with the LDAP provider, see Creating a User.
The following code example creates a new user and a sets important properties for that user.
' Set up property values for the new user Dim sUsername ' String that will contain the username Dim sFullName ' String that will contain the user's full name Dim sDescription ' String that will contain a description of the user Dim sPassword ' String that will contain the user's password Dim sComputerName ' String that contains the name of the computer On Error Resume Next ' Insert code that will safely retrieve the username, full name, ' description, password, and computer name. Set myComputer = GetObject("WinNT://" & sComputerName) If Err.Number<>0 Then MsgBox ("An error has occurred.") Set myComputer = Nothing Exit Sub End If ' Create the new user account Set newUser = myComputer.Create("user", sUsername) If Err.Number<>0 Then MsgBox ("An error has occurred.") Set myComputer = Nothing Set newUser = Nothing Exit Sub End If ' Set properties in the new user account newUser.SetPassword sPassword newUser.FullName = sFullName newUser.Description = sDescription newUser.SetInfo Set newUser = Nothing Set myComputer = Nothing