NBCOLLEGE
asked on
Convert from VB Script to VB6
I have the following to add users any ideas how to convert it from script to VB6?
On Error Resume Next
Dim WshShell
Dim importFilename
Dim exceptionFilename
Dim container
Dim stafforstudent
Dim whichsite
Dim domain
Dim env
Dim userObject
Dim fileServer
Dim fso
Dim fileHandle
Dim fileHandle2
Dim lineOText
Dim readUN
Dim readFN
Dim readSN
Dim readDOB
Dim readAdd1
Dim readAdd2
Dim readAdd3
Dim readPOBox
Dim readTel
Dim readCO
Dim firstName
Dim lastName
Dim space
Dim suffix
Dim adBound
Dim ouBound
Dim ouGroups
Set WshShell = WScript.CreateObject("WScr ipt.Shell" )
Set env=WshShell.Environment(" PROCESS")
importFilename=InputBox("P lease enter the name of the file to import:","Import Users")
If importFilename="" Then WScript.Quit(1)
exceptionFilename=InputBox ("Please enter the name of the exception file that will contained failed additions:","Import Users",Left(importFilename ,Len(impor tFilename) -4)+"_exce ptions.csv ")
If exceptionFilename="" Then WScript.Quit(1)
suffix="nbcollege.ac.uk"
stafforstudent=InputBox("P lease enter Staff or Students:","Import Users","Students")
If stafforstudent="" Then WScript.Quit(1)
whichsite=InputBox("Please enter the which site to create the users E.G Broadwater,Durrington,etc: ","Import Users","Broadwater")
If whichsite="" Then WScript.Quit(1)
fileserver=InputBox("Pleas e enter the location of the home directory E.G wdfs01 or bwfs01:","Import Users","bwfs01")
If fileserver="" Then WScript.Quit(1)
domain="LDAP://nbcollege.a c.uk"
WScript.Echo "Connecting to "+domain+"..."
Set adBound=GetObject(domain)
If Err Then
WScript.Echo "Unable to connect!"
WScript.Sleep(5000)
WScript.Quit(1)
End If
WScript.Echo "Connected to "+domain
Set ouBound=adBound.GetObject( "Organizat ional Unit", "ou="+whichsite+",ou="+sta fforstuden t+",ou=use rs,ou=reso urces")
If Err Then
WScript.Echo "Unable to bind to org unit!"
WScript.Sleep(5000)
WScript.Quit(1)
End If
Set fso=CreateObject("Scriptin g.FileSyst emObject")
Set fileHandle=fso.OpenTextFil e(importFi lename,1)
If Err Then
WScript.Echo "Unable to open import file!"
WScript.Sleep(5000)
WScript.Quit(1)
End If
Set fileHandle2=fso.CreateText File(excep tionFilena me,1)
If Err Then
WScript.Echo "Unable to create exception file!"
fileHandle.Close
WScript.Sleep(5000)
WScript.Quit(1)
End If
While Not(fileHandle.AtEndOfStre am)
lineOText=fileHandle.ReadL ine
If lineOText<>"" Then
readUN=GetField(lineOText)
readSN=GetField(lineOtext)
readFN=GetField(lineOText)
readDOB=GetField(lineOText )
readAdd1=GetField(lineOTex t)
readAdd2=GetField(lineOTex t)
readAdd3=GetField(lineOTex t)
readPOBox=GetField(lineOTe xt)
readTel=GetField(lineOText )
readCO=GetField(lineOText)
If readFN="" Then readFN="-"
If readSN="" Then readSN="-"
If readDOB="" Then readDOB="-"
If readAdd1="" Then readAdd1="-"
If readAdd2="" Then readAdd2="-"
If readAdd3="" Then readAdd3="-"
If readPOBox="" Then readPOBox="-"
If readTel="" Then readTel="-"
If readCO="" Or readCO="---" Then readCO="No Course Code"
WScript.Echo "Username: "+readUN
WScript.Echo "Surname: "+readSN
WScript.Echo "Firstname: "+readFN
WScript.Echo "DOB: "+readDOB
WScript.Echo "Address1: "+readAdd1
WScript.Echo "Address2: "+readAdd2
WScript.Echo "Address3: "+readAdd3
WScript.Echo "POBOx: "+readPOBox
WScript.Echo "Tel: "+readTel
WScript.Echo "Course Code: "+readCO
WScript.Echo "First Name: "+firstName
WScript.Echo "Surname: "+lastName
Set userObject=ouBound.Create( "User","cn ="+readUN+ " - "+readFN+" "+readSN)
If Err Then
WScript.Echo "Unable to create user!"
fileHandle2.WriteLine readUN+","+readSN+","+read DOB+","+re adAdd1+"," +readAdd2+ ","+readAd d3+","+rea dPOBox+"," +readTel+" ,"+readCO
Err.Clear
Else
userObject.UserPrincipalNa me=readUN+ "@"+suffix
userObject.FullName=readFN +" "+readSN
If firstName<>"" Then userObject.GivenName=first Name
userObject.Firstname=readF N
userObject.LastName=readSN
userObject.SamAccountName= readUN
userObject.pager=readDOB+" , Date of Birth"
userObject.streetAddress=r eadAdd1+" "+readAdd2+" "+readAdd3
userObject.postalCode=read POBox
userObject.homePhone=readT el
userObject.HomeDrive="H:"
userObject.Description=rea dCO+" - Course"
userObject.HomeDirectory=" \\"+fileSe rver+"\"+s tafforstud ent+"$\"+r eadUN+"\Ho me"
userObject.ProfilePath="\\ "+fileServ er+"\"+sta fforstuden t+"$\"+rea dUN+"\Prof ile"
' userObject.TerminalService sProfilePa th="\\"+fi leServer+" \"+staffor student+"$ \"+readUN+ "\TSProfil e"
userObject.SetInfo
If Err Then
WScript.Echo "Unable to set user info!"
fileHandle2.WriteLine readUN+","+readSN+","+read DOB+","+re adAdd1+"," +readAdd2+ ","+readPO Box+","+re adTel+","+ readCO
Err.Clear
Else
userObject.SetPassword "password"
userObject.PwdLastSet=0
userObject.AccountDisabled =False
userObject.SetInfo
fso.CreateFolder "\\"+fileServer+"\"+staffo rstudent+" $\"+readUN
fso.CreateFolder "\\"+fileServer+"\"+staffo rstudent+" $\"+readUN +"\Home"
fso.CreateFolder "\\"+fileServer+"\"+staffo rstudent+" $\"+readUN +"\Profile "
fso.CreateFolder "\\"+fileServer+"\"+staffo rstudent+" $\"+readUN +"\Home\My Documents"
fso.CreateFolder "\\"+fileServer+"\"+staffo rstudent+" $\"+readUN +"\Home\My Documents\My Pictures"
' WshShell.Run "cmd.exe /c echo y|cacls \\"+fileServer+"\"+staffor student+"$ \"+readUN+ " /t /g "+readUN+":c 'administrators:f SYSTEM:f",0
WshShell.Run "cmd.exe /c echo y|xcacls \\"+fileServer+"\"+staffor student+"$ \"+readUN+ " /t /g "+readUN+":c administrators:f sec-ManageStudentData:c Sec-Readstudentdata:r SYSTEM:f ",0
WScript.Echo "The user, home directory and profile directory have been successfully created."
WScript.Echo "Adding user to groups..."
Set ouGroups=GetObject("LDAP:/ /OU=Course Groups,OU=Groups,OU=Resour ces,DC=nbc ollege,DC= ac,DC=uk")
Set groupObject=RSCGetGroup(re adCO,ouGro ups)
groupObject.Add userObject.ADsPath
WScript.Echo "User has been added to group '"+readCO+"'"
End If
End If
End If
Wend
fileHandle.Close
fileHandle2.Close
WScript.Sleep(5000)
Function GetField(ByRef inputText)
Dim comma
comma=Instr(inputText,",")
If comma=0 Then
GetField=inputText
inputText=""
Else
GetField=Left(inputText,co mma-1)
inputText=Mid(inputText,co mma+1)
End If
End Function
Function RSCGetGroup(groupname,ByRe f ouBound)
On Error Resume Next
Set RSCGetGroup=ouBound.GetObj ect("Group ","cn="+gr oupname)
If Err Then
Err.Clear
WScript.Echo "Creating group '"+groupname+"'"
Set RSCGetGroup=ouBound.Create ("Group"," cn="+group name)
If Err Then
WScript.Echo "Unable to create group '"+groupname+"' ("+CStr(Err.Number)+")"
WScript.Echo "Please add the user to the appropriate groups using the User Management utility"
Err.Clear
Exit Function
End If
RSCGetGroup.SamAccountName =groupname
RSCGetGroup.SetInfo
If Err Then
WScript.Echo "Unable to set group info '"+groupname+"' ("+CStr(Err.Number)+")"
WScript.Echo "Please add the user to the appropriate groups using the User Management utility"
Err.Clear
Exit Function
End If
Else
WScript.Echo "Located group '"+groupname+"'"
End If
End Function
On Error Resume Next
Dim WshShell
Dim importFilename
Dim exceptionFilename
Dim container
Dim stafforstudent
Dim whichsite
Dim domain
Dim env
Dim userObject
Dim fileServer
Dim fso
Dim fileHandle
Dim fileHandle2
Dim lineOText
Dim readUN
Dim readFN
Dim readSN
Dim readDOB
Dim readAdd1
Dim readAdd2
Dim readAdd3
Dim readPOBox
Dim readTel
Dim readCO
Dim firstName
Dim lastName
Dim space
Dim suffix
Dim adBound
Dim ouBound
Dim ouGroups
Set WshShell = WScript.CreateObject("WScr
Set env=WshShell.Environment("
importFilename=InputBox("P
If importFilename="" Then WScript.Quit(1)
exceptionFilename=InputBox
If exceptionFilename="" Then WScript.Quit(1)
suffix="nbcollege.ac.uk"
stafforstudent=InputBox("P
If stafforstudent="" Then WScript.Quit(1)
whichsite=InputBox("Please
If whichsite="" Then WScript.Quit(1)
fileserver=InputBox("Pleas
If fileserver="" Then WScript.Quit(1)
domain="LDAP://nbcollege.a
WScript.Echo "Connecting to "+domain+"..."
Set adBound=GetObject(domain)
If Err Then
WScript.Echo "Unable to connect!"
WScript.Sleep(5000)
WScript.Quit(1)
End If
WScript.Echo "Connected to "+domain
Set ouBound=adBound.GetObject(
If Err Then
WScript.Echo "Unable to bind to org unit!"
WScript.Sleep(5000)
WScript.Quit(1)
End If
Set fso=CreateObject("Scriptin
Set fileHandle=fso.OpenTextFil
If Err Then
WScript.Echo "Unable to open import file!"
WScript.Sleep(5000)
WScript.Quit(1)
End If
Set fileHandle2=fso.CreateText
If Err Then
WScript.Echo "Unable to create exception file!"
fileHandle.Close
WScript.Sleep(5000)
WScript.Quit(1)
End If
While Not(fileHandle.AtEndOfStre
lineOText=fileHandle.ReadL
If lineOText<>"" Then
readUN=GetField(lineOText)
readSN=GetField(lineOtext)
readFN=GetField(lineOText)
readDOB=GetField(lineOText
readAdd1=GetField(lineOTex
readAdd2=GetField(lineOTex
readAdd3=GetField(lineOTex
readPOBox=GetField(lineOTe
readTel=GetField(lineOText
readCO=GetField(lineOText)
If readFN="" Then readFN="-"
If readSN="" Then readSN="-"
If readDOB="" Then readDOB="-"
If readAdd1="" Then readAdd1="-"
If readAdd2="" Then readAdd2="-"
If readAdd3="" Then readAdd3="-"
If readPOBox="" Then readPOBox="-"
If readTel="" Then readTel="-"
If readCO="" Or readCO="---" Then readCO="No Course Code"
WScript.Echo "Username: "+readUN
WScript.Echo "Surname: "+readSN
WScript.Echo "Firstname: "+readFN
WScript.Echo "DOB: "+readDOB
WScript.Echo "Address1: "+readAdd1
WScript.Echo "Address2: "+readAdd2
WScript.Echo "Address3: "+readAdd3
WScript.Echo "POBOx: "+readPOBox
WScript.Echo "Tel: "+readTel
WScript.Echo "Course Code: "+readCO
WScript.Echo "First Name: "+firstName
WScript.Echo "Surname: "+lastName
Set userObject=ouBound.Create(
If Err Then
WScript.Echo "Unable to create user!"
fileHandle2.WriteLine readUN+","+readSN+","+read
Err.Clear
Else
userObject.UserPrincipalNa
userObject.FullName=readFN
If firstName<>"" Then userObject.GivenName=first
userObject.Firstname=readF
userObject.LastName=readSN
userObject.SamAccountName=
userObject.pager=readDOB+"
userObject.streetAddress=r
userObject.postalCode=read
userObject.homePhone=readT
userObject.HomeDrive="H:"
userObject.Description=rea
userObject.HomeDirectory="
userObject.ProfilePath="\\
' userObject.TerminalService
userObject.SetInfo
If Err Then
WScript.Echo "Unable to set user info!"
fileHandle2.WriteLine readUN+","+readSN+","+read
Err.Clear
Else
userObject.SetPassword "password"
userObject.PwdLastSet=0
userObject.AccountDisabled
userObject.SetInfo
fso.CreateFolder "\\"+fileServer+"\"+staffo
fso.CreateFolder "\\"+fileServer+"\"+staffo
fso.CreateFolder "\\"+fileServer+"\"+staffo
fso.CreateFolder "\\"+fileServer+"\"+staffo
fso.CreateFolder "\\"+fileServer+"\"+staffo
' WshShell.Run "cmd.exe /c echo y|cacls \\"+fileServer+"\"+staffor
WshShell.Run "cmd.exe /c echo y|xcacls \\"+fileServer+"\"+staffor
WScript.Echo "The user, home directory and profile directory have been successfully created."
WScript.Echo "Adding user to groups..."
Set ouGroups=GetObject("LDAP:/
Set groupObject=RSCGetGroup(re
groupObject.Add userObject.ADsPath
WScript.Echo "User has been added to group '"+readCO+"'"
End If
End If
End If
Wend
fileHandle.Close
fileHandle2.Close
WScript.Sleep(5000)
Function GetField(ByRef inputText)
Dim comma
comma=Instr(inputText,",")
If comma=0 Then
GetField=inputText
inputText=""
Else
GetField=Left(inputText,co
inputText=Mid(inputText,co
End If
End Function
Function RSCGetGroup(groupname,ByRe
On Error Resume Next
Set RSCGetGroup=ouBound.GetObj
If Err Then
Err.Clear
WScript.Echo "Creating group '"+groupname+"'"
Set RSCGetGroup=ouBound.Create
If Err Then
WScript.Echo "Unable to create group '"+groupname+"' ("+CStr(Err.Number)+")"
WScript.Echo "Please add the user to the appropriate groups using the User Management utility"
Err.Clear
Exit Function
End If
RSCGetGroup.SamAccountName
RSCGetGroup.SetInfo
If Err Then
WScript.Echo "Unable to set group info '"+groupname+"' ("+CStr(Err.Number)+")"
WScript.Echo "Please add the user to the appropriate groups using the User Management utility"
Err.Clear
Exit Function
End If
Else
WScript.Echo "Located group '"+groupname+"'"
End If
End Function
Pretty generic question. What specifically in that code can't you replicate in VB6?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
NBCOLLEGE:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.