Re: Add multiple local user accounts




<msmucny2@xxxxxxxxx> wrote in message
news:1190657853.611575.324910@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I am searching for a script that will allow me to add multiple local
user accounts to a PC and set their passwords to never expire. i've
found the line which sets the password to never expire, however, i've
never used VB to add a local user to the machine. i previously
created a batch file to create all the user's using the "net user"
command however, you cannot set the password to never expire using
that command. any help is appreciated.


The trick is you must use the WinNT provider for local accounts. The local
SAM account database is not LDAP compliant. The code to create one user
would be similar to:
=============
Option Explicit
Dim strComputer, objComputer, strName, objUser
Dim strFullName, lngFlag, strPassword

Const ADS_UF_DONT_EXPIRE_PASSWD = &H10000

' Specify local computer.
' This could also be retrieved from the wshNetwork object programmatically.
strComputer = "MyComputer"

' Bind to the local computer object.
Set objComputer = GetObject("WinNT://" & strComputer)

' Specify local user name.
strName = "JSmith"

' Create local user object.
Set objUser = objComputer.Create("user", strName)

' Assign properties, like Full Name.
strFullName = "Jim Smith"
objUser.Put "FullName", strFullName

' Save the user object.
objUser.SetInfo

' Set password
strPassword = "zyx321"
objUser.SetPassword strPassword

' Set user flag so password never expires.
lngFlag = objUser.Get("UserFlags")
lngFlag = lngFlag Or ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put "UserFlags", lngFlag

' Save change.
objUser.SetInfo
=============
To do this for multiple users you need to either prompt for the required
values, or read them either from a text file or a spread***. Values needed
are User Name, other property values like Full Name, and password. The name
of the local computer can be retrieved using:

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

If you run this script on a remote computer (assuming you have permissions)
you must specify the NetBIOS name of the computer.

The names of properties exposed by the WinNT provider are documented in the
fourth spread*** on this page:

http://www.rlmueller.net/UserAttributes.htm

An example VBScript program that reads values from a spread*** is linked
here:

http://www.rlmueller.net/Read%20from%20Excel.htm

Reading the values from a text file can also be done, but you would probably
have the values for each user in a line, one line per user. The values must
be delimited. The following example reads one value from each line in a text
file:

http://www.rlmueller.net/Add%20Users%20to%20Group%201.htm

If the values are space or comma delimited, you can use the Split function
to parse each line of the text file into an array. Something like:

' Read one line of text file.
strLine = Trim(objFile.ReadLine
' Parse the comma delimited values into an array.
arrValues = Split(strLine, ",")

If the file is a csv file, where comma delimited values can be quoted, I
have an example program to read such a file linked here:

http://www.rlmueller.net/ReadCSV.htm

--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--


.