Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create user accounts

Status
Not open for further replies.

glenmac

Technical User
Jul 3, 2002
947
CA
Hi,I'm new to creating users. I'd like to create a program that opens an excel file and creates a user from each row. It takes the last name and the first name and creates a user account on my local machine (Using WinNT provider). Each account should be in the format of “last name, first initial”. For example, the first account listed above (Joe Bloe) should have the user account “BloeJ”. Each account should have the following specifications, Initial password is the user’s age.Initial password must be changed.

First Name Last Name Age
Jerry Berry 21
Larry White 30
Susan Brown 45

All help would be greatly appreciated!
 
Got this far but what I'd like to do is combine the two scripts below. I don't know the syntax for saving a file automatically. I've used Spreadsheets to enter the data.
Script 1

Dim objXL
Set objXL = WScript.CreateObject("Excel.Application") ' Open an instance of Excel

objXL.Visible = TRUE ' makes it visible

objXL.WorkBooks.Add ' allows data to be added


for x = 1 to 3 'loop for fixing a set column width
objXL.Columns(x).ColumnWidth = 25 ' set the column 'width
next

'Adding Headings to our spreadsheet document
objXL.Cells(1, 1).Value = "First Name" ' adds values to the cells
objXL.Cells(1, 2).Value = "Last Name"
objXL.Cells(1, 3).Value = "Age"

'Allows a range of cell formatting
objXL.Range("A1:C1").Select 'Selects a range of cells
objXL.Selection.Font.Bold = True 'Bolds the main headings
objXL.Selection.Interior.ColorIndex = 1 'Produces an interior colour
objXL.Selection.Interior.Pattern = 1 'Allows a solid pattern in Excel
objXL.Selection.Font.ColorIndex = 2 'Changes font from black to white


x=2
do

first = InputBox("Enter First Name","","First Name")'input area
last = InputBox("Enter last Names","","Last Name")
Age= InputBox("Enter age","","Age")
'For y =1 to 2
objXL.Cells(x, 1).Value = first
objXL.Cells(x, 2).Value = last
objXL.Cells(x, 3).Value = Age
x=x+1
continue = MsgBox("Do you want o continue?",4)
Loop While continue = 6 'loop while the user indicates yes
'objXL.Save "C:\test.xls"

Script 2

Function createUser()
row =2 ' set initial row number
objXL.ActiveSheet.range("A2").Activate
Do While objXL.activecell.Value <> &quot;&quot; 'Loop until we run out of rows
firstName = objXL.activecell(row, 1).Value 'assigning first names to this column
lastName = objXL.Cells(row, 2).Value 'assigning last names to this column
age = objXL.Cells(row, 3).Value 'assigning ages to this column
initial = LCase(Left(firstName, 1)) 'getting the first letter from first name
'and converting it to lowercase
userName = LCase(lastName) & initial 'assigning lowercase last name & initial
'to the userName
bothName = firstName & &quot; &quot; & lastName 'Building the Users Full Name
Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
compName = WshShell.ExpandEnvironmentStrings(&quot;%COMPUTERNAME%&quot;) 'assigns computername to a variable
Set obj=GetObject(&quot;WinNT://&quot; & compName) 'access local computer with compName variable
Set usr = obj.Create(&quot;user&quot;, userName) 'create user
usr.SetPassword(grade) 'set password
usr.Put &quot;PasswordExpired&quot;, 1 'set password to expire, requires user to change
'password at first logon
usr.Fullname = bothName 'set Full Name to users profile
usr.Description = &quot;GuestUser&quot; 'set Description to users profile
usr.SetInfo 'commit changes
set usr=nothing 'clean up usr variable
set obj=nothing 'clean up obj variable
row = row + 1 ' go down to next row
objXL.Cells(row, 1).Select ' select cell
Loop
End Function

call createUser()

Hope someone can help
 
For anyone interested this script adds a user without the use of an excel spreadsheet.

firstname=inputbox(&quot;Users first name&quot;)
lastname=inputbox(&quot;Users Last name&quot;)
psswd = inputbox(&quot;Enter Password&quot;)

initial = LCase(Left(firstName, 1))

Set WshShell = WScript.CreateObject(&quot;WScript.Shell&quot;)
compName = WshShell.ExpandEnvironmentStrings(&quot;%COMPUTERNAME%&quot;) 'assigns computername to a variable
userName = LCase(lastName) & initial 'assigning lowercase last name & initial
'to the userName
bothName = firstName & &quot; &quot; & lastName 'Building the students Full Name
Set obj=GetObject(&quot;WinNT://&quot; & compName) 'access local computer with compName variable
Set usr = obj.Create(&quot;user&quot;, userName) 'create user
usr.SetPassword(psswd) 'set password
usr.Put &quot;PasswordExpired&quot;, 1 'set password to expire, requires user to change
'password at first logon
usr.Fullname = bothName 'set Full Name to users profile
usr.Description = &quot;Guest&quot; 'set Description to users profile
usr.SetInfo 'commit changes
set usr=nothing 'clean up usr variable
set obj=nothing 'clean up obj variable
Msgbox(&quot;User has been Added&quot;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top