Question Locked

Create User account... soooo close...

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm creating a create user script, and everything works up to setting the user home folder permissions. it's a sub in a much larger piece of work, I'm just out of ideas on getting these permissions to set. Thank you in advance.

===============================================

'\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
' \\\\CREATE USER SUBROUTINE\\\\\
' \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Sub create(arrCampus,strTopOU,strLogin,strFirNm,strLasNm,strCmp,strEmpID)

'On Error Resume Next

' Set user-level dependant variables based on staff or student status.

if strTopOU="staff" then
strTopOU="StaffAccounts"
strHome="\\NOC-FPVS2\Faculty-StaffHome\" & strLogin
strCmpGrp = "LDAP://CN="&strCmp&"-Access,OU="&strCmp&",OU="&strTopOU&",DC=ectorcountyisd,DC=org"
strLvlGrp = "LDAP://CN=Staff,OU="&strTopOU&",DC=ectorcountyisd,DC=org"
else
strTopOU="StudentAccounts"
strHome="\\NOC-FPVS1\StudentHome\" & strLogin
strCmpGrp = "LDAP://CN="&strCmp&"-Students,OU="&strCmp&",OU="&strTopOU&",DC=ectorcountyisd,DC=org"
strLvlGrp = "LDAP://CN=Students,OU="&strTopOU&",DC=ectorcountyisd,DC=org"
end if

' Construct the other variables needed to create the account
strPass = "P@55w0rd1"
strDN = "LDAP://OU=" & strCmp & ",OU=" & strTopOU & ",DC=ectorcountyisd,DC=org"

' Create the user account
Set objContainer = GetObject(strDN)
Set objUser = objContainer.Create("User", "cn=" & strLogin)
objUser.sAMAccountName = strLogin
objUser.userPrincipalName = strLogin & "@ectorcountyisd.org"
objUser.SetInfo

' Save the user account basic info and them populate the rest of the needed fields.
objUser.GetInfo
objUser.givenName = strFirNm
objUser.sn = strLasNm
objUser.displayName = strLasNm&", "&strFirNm
objUser.homeDrive = "U:"
objUser.homeDirectory = strHome
objUser.employeeID = strEmpID
objUser.department = arrCampus(strCmp)
objUser.mail = strLogin & "@ectorcountyisd.org"

' If it's a teacher, don't set Password must be changed at next login. If it's a student, have them change it.
if strTopOU="StaffAccounts" then
objUser.pwdLastSet = CLng(-1)
else
objUser.pwdLastSet = CLng(0)
end If

objUser.SetPassword strPass
objUser.AccountDisabled = False
objUser.SetInfo

' Add the user to the appropriate groups
Set objGroup = GetObject(strCmpGrp)
objGroup.add(objUser.ADsPath)
objGroup.SetInfo

Set objGroup = GetObject(strLvlGrp)
objGroup.add(objUser.ADsPath)
objGroup.SetInfo

exist = isExist(strLogin)

if exist = 0 then
do until exist = 1
wscript.sleep(2000)
exist = isExist(strLogin)
Loop
end if

strDirectory = strHome
Set fileSys = CreateObject("Scripting.FileSystemObject")
Set objFolder = fileSys.CreateFolder(strDirectory)

'#### Stops working here ####

do until objFSO.FolderExists(strHome)
wscript.sleep(2000)
Loop

' Assign user permission to home folder.
Set objShell = CreateObject("Wscript.Shell")
intRunError = objShell.Run("%COMSPEC% /c Echo Y| cacls " _
& strHome & "/e /c /g "&strLogin&":F ", 2, True)

' Finished account creation for AD user.

End Sub

2 replies

by chris.saintours

After some msgboxing, more debugging, and a lesson from Perl (TIMTOWTDI) I replaced COMSPEC with cmd, made sure there was a space before the /e, added the domain onto strLogin and away I went!

This discussion is closed to new replies.