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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Home Folder Creation??

Status
Not open for further replies.

teckystuff

Technical User
Joined
Jan 26, 2006
Messages
289
Location
ZA
Hey Guys, I am new to VBS and have been trying to find a script that will help me create home folder directories for a large amount of users automatically. I would also like to set the security on each folder. I found this script but am not sure if it will do what I want it to do. I dont have a test enviroment at the moment and am hesitant to run it on my production domain.
PS: This domain is still a NT4 domain.

Any help appreciated.

Code:
Sub GetParentDir
  ParentDir = InputBox("Type the path of the parent folder for the user folders:", "Parent Directory Input Prompt", ParentDir)
  If Not FS.FolderExists(ParentDir) Then
    GetParentDir
  End If
End Sub

Dim WSHNetwork, WSHShell, FS, Domain, DomainObj, Computer, ShareServiceObj, ParentDir, Hidden, Drive
Set FS = CreateObject("Scripting.FileSystemObject")
Set WSHNetwork = CreateObject("WScript.Network")
Set ShareServiceObj = GetObject("WinNT://" & WSHNetwork.ComputerName & "/LanManServer")
 
Domain = InputBox("Type the name of your domain:","Enumeration and Creation of User Shares","DomainName")
ParentDir = "C:\Users"
GetParentDir
Hidden = MsgBox("Do you want the user shares to be hidden? If yes, the share will be username$; If no, the share will be username", 4, "Hidden Shares?")
Hidden = Hidden - 7
Drive = InputBox("What drive letter do you want to map the home folder to?", "Drive Letter?", "X:")
Set DomainObj = GetObject("WinNT://" & Domain)
DomainObj.Filter = Array("User")

For Each UserObj in DomainObj
  Dim ShareName
  If Not FS.FolderExists(ParentDir & "\" & UserObj.Name) Then
    FS.CreateFolder(ParentDir & "\" & UserObj.Name)
  End If
  ShareName = UserObj.Name
  If Hidden Then
    ShareName = ShareName & "$"
  End If
  On Error Resume Next
  Set NewShare = ShareServiceObj.Create("fileshare", ShareName)
  If Not Err Then
    NewShare.Path = ParentDir & "\" & UserObj.Name
    NewShare.MaxUserCount = 1 'Sets the limit for the number of user connections
    NewShare.SetInfo
    UserObj.HomeDirectory = "\\" & WSHNetwork.ComputerName & "\" & ShareName
    UserObj.HomeDirDrive = Drive 'Requires ADSI 2.5
    UserObj.SetInfo
  End If
Next

MsgBox "Script Complete",, "Finished"

*****************************************
Your mouse has moved - reboot for changes to take effect
 
You might want to take a look at this thread for some additional ideas. thread96-1240843

Some of the script you posted won't work since you don't have AD.

You can use VBScript as long as you have installed WSH 5.6 but you can't use anything that looks for ADSI.





I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top