Create Local User Account via Input

You can add this script to your imaging process to create a local user account.

Dim strUserFirst,StrUserLast,strPass, CombinedUserName

Set objShell = CreateObject(“Wscript.Shell”)
Set objEnv = objShell.Environment(“Process”)
strComputer = objEnv(“COMPUTERNAME”)
‘msgbox strComputer
GetInfo()

Sub GetInfo()
on error resume next
strUserFirst = inputbox(“Please enter your first name”,”Account Setup”)

If IsEmpty(strUserFirst) Then
MsgBox “You cannot cancel the account setup.”
GetInfo()
ElseIf Len(strUserFirst) = 0 Then
MsgBox “You Clicked OK but left the box blank”
GetInfo()
End If

strUserLast = inputbox(“Please enter your last name.”,”Account Setup”)
If IsEmpty(strUserLast) Then
MsgBox “You cannot cancel the account setup.”
GetInfo()
ElseIf Len(strUserLast) = 0 Then
MsgBox “You Clicked OK but left the box blank”
GetInfo()
End If

strPass = inputbox(“Enter the password for the new account.”,”Account Setup”)
If IsEmpty(strPass) Then
MsgBox “You cannot cancel the account setup.”
GetInfo()
ElseIf Len(strPass) = 0 Then
MsgBox “You Clicked OK but left the box blank”
GetInfo()
End If

‘Trim white space
strUserFirst=Trim(strUserFirst)
strUserLast=Trim(strUserLast)
strPass=Trim(strPass)
strUserFirstInitial = Left(strUserFirst, 1)
CombinedUserName = strUserFirstInitial & strUserLast
‘Msgbox CombinedUserName

CheckResponse()
end sub

Sub CheckResponse()

intAnswer = _
Msgbox(“Is this the correct information? ” & chr(13) & chr(13) _
& “First Name: ” & strUserFirst & chr(13) & “Last Name: ” & strUserLast & chr(13) & “Password: ” & strPass _
,vbYesNo, “Account Setup”)

If intAnswer = vbYes Then
‘Msgbox “OK. Account is being setup.”
CreateAccount()
ExitNow()
Else
Msgbox “Please re-enter your account information.”
GetInfo()
End If
end sub

Sub ExitNow()
Wscript.quit
end sub

Sub CreateAccount()
Set colAccounts = GetObject(“WinNT://” & strComputer & “,computer”)

Set objUser = colAccounts.Create(“user”, CombinedUserName)

objUser.SetPassword strPass

Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
objPasswordExpirationFlag = ADS_UF_DONT_EXPIRE_PASSWD
objUser.Put “userFlags”, objPasswordExpirationFlag

objUser.SetInfo
Set Group = GetObject(“WinNT://” & strComputer & “/Administrators,group”)
Group.Add(objUser.ADspath)
End Sub

email me