Computing.Net > Forums > Programming > VBscripting to create folders

Computing.Net: Over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to sign up now, it's free!

VBscripting to create folders

Reply to Message Icon

Original Message
Name: kiwi_hk
Date: September 26, 2005 at 08:54:36 Pacific
Subject: VBscripting to create folders
OS: WIndows 2003
CPU/Ram: 2G
Comment:

Hi
I downloaded the VBscript file to create folders for my users in AD, but I am not a VBS programmer, can anybody help me in changing it so I can use a specific OU to create the folders. At the moment it creates the whole domain. Here is the script from Microsoft Q234746

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"

By the way the script doesn't actually share the folders out in Windows 2003, it just create them, even though it ask me to shared them with a hidden $.

Thanks

Ken


Report Offensive Message For Removal


Response Number 1
Name: Michael J (by mjdamato)
Date: September 26, 2005 at 13:46:27 Pacific
Reply: (edit)

OU?

Michael J


Report Offensive Follow Up For Removal

Response Number 2
Name: kiwi_hk
Date: September 26, 2005 at 19:41:15 Pacific
Reply: (edit)

Hi

It's for a server. eg. Windows 2003 server.

OU is Organization unit.

I have created one for my users,

Ken


Report Offensive Follow Up For Removal







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home








Do you have your own blog?

Yes
No
I did before
I will soon


View Results

Poll Finishes In 4 Days.
Discuss in The Lounge
Poll History




Data Recovery Software